Skip to content

Commit 473a4c6

Browse files
authored
feat(usb_midi): Enhance USBMIDI with device name
1 parent fdd6ccd commit 473a4c6

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

libraries/USB/src/USBMIDI.h

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,53 @@ typedef struct {
1818
} midiEventPacket_t;
1919

2020
class USBMIDI {
21+
private:
22+
static const char* deviceName;
23+
static char nameBuffer[32]; // Buffer to store the device name
24+
/**
25+
* @brief Get the default device name
26+
* @return Default name "TinyUSB MIDI" if no other name is set
27+
*/
28+
static const char* getDefaultDeviceName() {
29+
return "TinyUSB MIDI";
30+
}
31+
2132
public:
22-
USBMIDI(String devDescName = "TinyUSB MIDI");
33+
/**
34+
* @brief Default constructor
35+
* Will use the compile-time name if set via SET_USB_MIDI_DEVICE_NAME(),
36+
* otherwise uses "TinyUSB MIDI"
37+
*/
38+
USBMIDI(void);
39+
40+
/**
41+
* @brief Constructor with custom device name
42+
* @param name The device name to use. This takes precedence over any
43+
* compile-time name set via SET_USB_MIDI_DEVICE_NAME()
44+
*/
45+
USBMIDI(const char* name);
46+
2347
void begin(void);
2448
void end(void);
49+
50+
/**
51+
* @brief Get the current device name
52+
* @return The device name in order of precedence:
53+
* 1. Name set via constructor (if any)
54+
* 2. Name set via SET_USB_MIDI_DEVICE_NAME() macro (if defined)
55+
* 3. Default name "TinyUSB MIDI"
56+
*/
57+
static const char* getCurrentDeviceName(void) {
58+
return deviceName ? deviceName : getDefaultDeviceName();
59+
}
60+
61+
/**
62+
* @brief Set the default name at compile time
63+
* @param name The name to set as default if no runtime name is provided
64+
*/
65+
static void setDefaultName(const char* name) {
66+
if (!deviceName) deviceName = name;
67+
}
2568

2669
/* User-level API */
2770

0 commit comments

Comments
 (0)