Skip to content

Commit 60e4a0b

Browse files
authored
feat(midi): USBMIDI class for device name
1 parent 1b4aea2 commit 60e4a0b

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

libraries/USB/src/USBMIDI.h

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,8 @@ typedef struct {
1919

2020
class USBMIDI {
2121
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-
}
22+
static char* midiUserDeviceName; // user device name
23+
static void setDeviceName(const char* name); // set user device name limites to 32 characters
3124

3225
public:
3326
/**
@@ -38,11 +31,15 @@ class USBMIDI {
3831
USBMIDI(void);
3932

4033
/**
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-
*/
34+
* @brief Set the current device name
35+
* 1. Name set via constructor (if any)
36+
* 2. Name set via SET_USB_MIDI_DEVICE_NAME() macro (if defined)
37+
* 3. Default name "TinyUSB MIDI"
38+
* It has no effect if name is set as NULL or ""
39+
*/
4540
USBMIDI(const char* name);
41+
42+
~USBMIDI();
4643

4744
void begin(void);
4845
void end(void);
@@ -53,18 +50,8 @@ class USBMIDI {
5350
* 1. Name set via constructor (if any)
5451
* 2. Name set via SET_USB_MIDI_DEVICE_NAME() macro (if defined)
5552
* 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-
}
53+
*/
54+
static const char* getCurrentDeviceName(void);
6855

6956
/* User-level API */
7057

0 commit comments

Comments
 (0)