7
7
#include " esp32-hal-tinyusb.h"
8
8
9
9
// Initialize static members
10
- char * USBMIDI::midiUserDeviceName = nullptr ;
10
+ char * USBMIDI::midiUserDeviceName = nullptr ;
11
11
// Weak definition of getUSBMIDIDefaultDeviceName to provide a default name
12
- __attribute__ ((weak)) const char* getUSBMIDIDefaultDeviceName() {
12
+ __attribute__ ((weak)) const char * getUSBMIDIDefaultDeviceName() {
13
13
return ESP32_USB_MIDI_DEFAULT_NAME;
14
14
}
15
15
@@ -49,25 +49,25 @@ USBMIDI::USBMIDI() {
49
49
}
50
50
51
51
// private function for setting a not null/empty MIDI device name limited to 32 characters
52
- void USBMIDI::setDeviceName (const char * name) {
53
- const uint8_t maxNameLength = 32 ; // tinyUSB Descriptor limit
54
- if (name != nullptr && strlen (name) > 0 ) {
55
- if (strlen (name) > maxNameLength) {
56
- log_w (" USBMIDI: Device name too long, truncating to %d characters." , maxNameLength);
57
- }
58
- if (!midiUserDeviceName) {
59
- midiUserDeviceName = new char [maxNameLength + 1 ]; // +1 for null-terminator
60
- }
61
- if (midiUserDeviceName) {
62
- strncpy (midiUserDeviceName, name, maxNameLength);
63
- // Ensure null-termination when overflowing
64
- midiUserDeviceName[maxNameLength] = ' 0円 ' ;
65
- } else {
66
- log_e (" USBMIDI: Failed to allocate memory for device name, using default name." );
67
- }
52
+ void USBMIDI::setDeviceName (const char *name) {
53
+ const uint8_t maxNameLength = 32 ; // tinyUSB Descriptor limit
54
+ if (name != nullptr && strlen (name) > 0 ) {
55
+ if (strlen (name) > maxNameLength) {
56
+ log_w (" USBMIDI: Device name too long, truncating to %d characters." , maxNameLength);
57
+ }
58
+ if (!midiUserDeviceName) {
59
+ midiUserDeviceName = new char [maxNameLength + 1 ]; // +1 for null-terminator
60
+ }
61
+ if (midiUserDeviceName) {
62
+ strncpy (midiUserDeviceName, name, maxNameLength);
63
+ // Ensure null-termination when overflowing
64
+ midiUserDeviceName[maxNameLength] = ' 0円 ' ;
68
65
} else {
69
- log_w (" USBMIDI: No device name provided , using default name [%s]. " , getUSBMIDIDefaultDeviceName () );
66
+ log_e (" USBMIDI: Failed to allocate memory for device name, using default name. " );
70
67
}
68
+ } else {
69
+ log_w (" USBMIDI: No device name provided, using default name [%s]." , getUSBMIDIDefaultDeviceName ());
70
+ }
71
71
}
72
72
73
73
/* *
@@ -77,7 +77,7 @@ void USBMIDI::setDeviceName(const char* name) {
77
77
* 3. Default name "TinyUSB MIDI"
78
78
* If device name is set as "", it will be ignored
79
79
*/
80
- USBMIDI::USBMIDI (const char * name) {
80
+ USBMIDI::USBMIDI (const char * name) {
81
81
if (!tinyusb_midi_interface_enabled) {
82
82
setDeviceName (name);
83
83
tinyusb_midi_interface_enabled = true ;
@@ -92,17 +92,17 @@ USBMIDI::~USBMIDI() {
92
92
delete[] midiUserDeviceName;
93
93
midiUserDeviceName = nullptr ;
94
94
}
95
- }
95
+ }
96
96
97
97
void USBMIDI::begin () {}
98
98
void USBMIDI::end () {}
99
99
100
- const char * USBMIDI::getCurrentDeviceName (void ) {
100
+ const char * USBMIDI::getCurrentDeviceName (void ) {
101
101
if (midiUserDeviceName) {
102
102
return midiUserDeviceName;
103
103
}
104
104
// If no user name set, use the compile-time default name limited to 32 characters
105
- setDeviceName (getUSBMIDIDefaultDeviceName ());
105
+ setDeviceName (getUSBMIDIDefaultDeviceName ());
106
106
if (midiUserDeviceName && strlen (midiUserDeviceName)) {
107
107
return midiUserDeviceName;
108
108
} else {
0 commit comments