int a = 10; int* p = &a; // p는 a의 주소를 저장
char str[] = "Piano"; char* p = str; // p == &str[0]
char names[3][12] = {"Piano", "Guitar", "Violin"};
const char* names[3] = {"Piano", "Guitar", "Violin"};
const char string_0[] PROGMEM = "Piano"; const char* const names[] PROGMEM = { string_0 };
// GM 악기 이름 (128개) const char* gmNames[128] = { "AcouPiano1", "AcouPiano2", "ElecGrand", "HonkyTonk", "ElecPiano1", "ElecPiano2", "Harpsi", "Clavi", // ... (중략) ... "Gunshot" }; // 드럼킷 이름 (9개, CleanWave32 기준) const char* drumKitNames[] = { "Standard", "Room", "Power", "Electronic", "TR-808", "Jazz", "Brush", "Orchestra", "SFX" }; // LCD 표시 예시 void renderLCD(uint8_t channel, uint8_t pc) { char line2[17]; if (channel == 10) { snprintf(line2, sizeof(line2), "D:%-10s", drumKitNames[pc]); } else { snprintf(line2, sizeof(line2), "%-12s %03d", gmNames[pc], pc); } lcd.setCursor(0, 1); lcd.print(line2); }
드럼킷은 이름뿐 아니라 MSB/LSB/Program Change 번호도 필요할 수 있음. 이 경우 구조체를 정의해서 더 체계적으로 관리 가능.
// 드럼킷 정보 구조체 struct DrumKit { const char* name; uint8_t msb; uint8_t lsb; uint8_t pc; }; // 드럼킷 배열 (CleanWave32 기준) const DrumKit drumKits[] = { {"Standard", 121, 0, 0}, {"Room", 121, 0, 1}, {"Power", 121, 0, 2}, {"Electronic", 121, 0, 3}, {"TR-808", 121, 0, 4}, {"Jazz", 121, 0, 5}, {"Brush", 121, 0, 6}, {"Orchestra", 121, 0, 7}, {"SFX", 121, 0, 8} }; // 드럼킷 선택 함수 void selectDrumKit(uint8_t index) { midiSendControlChange(0, drumKits[index].msb, 10); // CC#0 = MSB midiSendControlChange(32, drumKits[index].lsb, 10); // CC#32 = LSB midiSendProgramChange(drumKits[index].pc, 10); // PC lcd.setCursor(0,1); lcd.print(drumKits[index].name); }
요약: 포인터 배열을 쓰면 문자열 이름을 플래시에 두고 RAM은 주소만 저장하기 때문에 메모리를 크게 절약할 수 있다. 드럼킷은 단순히 이름만 관리할 수도 있지만, MSB/LSB/PC까지 구조체에 넣어 관리하면 MIDI 제어가 훨씬 깔끔해진다.
이 문서는 정해영의 아이디어와 지시에 따라 AI 도구(ChatGPT)의 도움을 받아 작성되었습니다.
본 문서는 Creative Commons CC0 1.0 Universal Public Domain Dedication에 따라 누구나 자유롭게 복제, 수정, 배포, 활용할 수 있으며, 출처 표시도 필요하지 않습니다. 다만, 내용의 정확성은 보장되지 않았으며, 정해영은 본 문서의 내용에 대해 어떠한 법적 책임도 지지 않습니다.
This document was written with the assistance of an AI tool (ChatGPT), based on the ideas and direction provided by Haeyoung Jeong.
It is released under the Creative Commons CC0 1.0 Universal Public Domain Dedication. Anyone may freely copy, modify, distribute, and use the content, with no requirement for attribution. However, the accuracy of the content is not guaranteed, and Haeyoung Jeong assumes no legal responsibility for its use.