---
name: "MusicTransformer"
mode: "api"
versionRequirements:
  - { name: "@ray-js/panel-sdk", version: "1.0.0" }
title: "MusicTransformer"
summary: "MusicTransformer is used to parse the lighting `music_data` DP and provides parsing and formatting for music data."
questions:
  - "What is MusicTransformer used for?"
  - "How does MusicTransformer parse music data?"
  - "What are the input and output of MusicTransformer?"
  - "What are the transformation rules of MusicTransformer?"
---

## MusicTransformer

> [VERSION] @ray-js/panel-sdk >= 1.0.0

> 💡 APP music rhythm DP for lighting products (e.g., music_data), converting parameters such as music mode, HSV values,
> white-light brightness and color temperature to and from a hexadecimal DP string.
> Protocol format: mode (1 digit) + hue (4 digits) + saturation (4 digits) + value (4 digits) + brightness (4 digits) + temperature (4 digits)

### Description

APP music standard DP protocol converter for bidirectional conversion between music rhythm data and the DP hexadecimal protocol

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `uuid` | `string` | No | DP identifier, defaults to 'music_data' |
| `defaultValue` | `TMusicData` | No | Default music data returned when parsing fails |

### Return Value

Type: `MusicTransformer`

MusicTransformer instance

#### Methods

| Method | Description |
| --- | --- |
| `parser` | Parse the DP hexadecimal string into a music data object |
| `formatter` | Format the music data object into a DP hexadecimal string |

### Referenced Types

##### `type` TMusicData

| Property | Type | Description |
| --- | --- | --- |
| `mode` | `number` | Mode |
| `hue` | `number` | Hue |
| `saturation` | `number` | Saturation |
| `value` | `number` | Brightness |
| `brightness` | `number` | White light brightness |
| `temperature` | `number` | Color temperature |


### Examples

#### Example

```ts
import { MusicTransformer } from '@ray-js/panel-sdk';

const transformer = new MusicTransformer();
// Parse DP string
const data = transformer.parser('0016803e803e803e803e8');
// => { mode: 0, hue: 360, saturation: 1000, value: 1000, brightness: 1000, temperature: 1000 }

// Format to DP string
const dpStr = transformer.formatter({ mode: 0, hue: 120, saturation: 800, value: 900, brightness: 500, temperature: 300 });
```
