Skip to content

Commit

Permalink
Add menu/logic to change string MIDI channel from tuning menu
Browse files Browse the repository at this point in the history
  • Loading branch information
KohlJary committed Sep 14, 2023
1 parent eb86d80 commit 039b46f
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 11 deletions.
14 changes: 10 additions & 4 deletions eeprom_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
// If you end up burning out one of the memory locations, you can shift them around
// by redefining the assingments here.

// The slots below should be arranged so that they are at least 20 apart. This is
// The slots below should be arranged so that they are at least 25 apart. This is
// to provide room for future upgrades. There may be two more channels later, as well
// as a second value (volume) for each channel.
//
// Teensy3.5 has 4096 bytes of EEPROM, so there's lots of room here.
static const int EEPROM_SLOT1 = 0;
static const int EEPROM_SLOT2 = 20;
static const int EEPROM_SLOT3 = 40;
static const int EEPROM_SLOT4 = 60;
static const int EEPROM_SLOT2 = 25;
static const int EEPROM_SLOT3 = 50;
static const int EEPROM_SLOT4 = 75;

// These define what the values are within the "slots". You'd add this to one of the
// SLOTs above to get the actual address in EEPROM.
Expand All @@ -37,6 +37,12 @@ static const int EEPROM_LOW_MEL_GROS = 14;
static const int EEPROM_TROMP_GROS = 15;
static const int EEPROM_DRONE_GROS = 16;
static const int EEPROM_BUZZ_GROS = 17;
static const int EEPROM_HI_MEL_CHAN = 18;
static const int EEPROM_LO_MEL_CHAN = 19;
static const int EEPROM_DRONE_CHAN = 20;
static const int EEPROM_TROMP_CHAN = 21;
static const int EEPROM_BUZZ_CHAN = 22;
static const int EEPROM_KEYCLICK_CHAN = 23;

// This int saves the play screen type. 0 = note + staff, 1 = note only;
static const int EEPROM_DISPLY_TYPE = 100;
Expand Down
12 changes: 12 additions & 0 deletions gurdystring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ int GurdyString::getVolume() {
return midi_volume;
};

/// @brief Sets a new channel for this string.
/// @param vol The new MIDI channel for this string. 1-16.
void GurdyString::setChannel(int cha) {
midi_channel = cha;
};

/// @brief Returns the string's MIDI channel.
/// @return The string's volume, 1-16
int GurdyString::getChannel() {
return midi_channel;
};

/// @brief Mutes/unmutes the string.
/// @param mute True = mute, false = unmute
/// @note While muted, soundOn/Off events do nothing. This exists for programming ease (calling sounOn() on all strings without checking if they are muted).
Expand Down
2 changes: 2 additions & 0 deletions gurdystring.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class GurdyString {
void setOpenNote(int new_note);
void setVolume(int vol);
int getVolume();
void setChannel(int cha);
int getChannel();
void setMute(bool mute);
bool getMute();
bool isPlaying();
Expand Down
16 changes: 15 additions & 1 deletion load_tunings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ void load_saved_tunings(int slot_num) {
value = EEPROM.read(slot + EEPROM_KEYCLICK_VOL);
mykeyclick->setVolume(value);

// MIDI Channels
value = EEPROM.read(slot + EEPROM_HI_MEL_CHAN);
mystring->setChannel(value);
value = EEPROM.read(slot + EEPROM_LO_MEL_CHAN);
mylowstring->setChannel(value);
value = EEPROM.read(slot + EEPROM_DRONE_CHAN);
mydrone->setChannel(value);
value = EEPROM.read(slot + EEPROM_TROMP_CHAN);
mytromp->setChannel(value);
value = EEPROM.read(slot + EEPROM_BUZZ_CHAN);
mybuzz->setChannel(value);
value = EEPROM.read(slot + EEPROM_KEYCLICK_CHAN);
mykeyclick->setChannel(value);

// Gros Modes
mystring->setGrosMode(EEPROM.read(slot + EEPROM_HI_MEL_GROS));
mylowstring->setGrosMode(EEPROM.read(slot + EEPROM_LOW_MEL_GROS));
Expand Down Expand Up @@ -175,4 +189,4 @@ void signal_scene_change(int scene_idx) {
// 0 = Do nothing
// While this should be 0, if there is bad data we'll just ignore it and do nothing.
}
};
};
6 changes: 6 additions & 0 deletions pause_screens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ void save_tunings(int slot) {
EEPROM.write(slot + EEPROM_TROMP_GROS, mytromp->getGrosMode());
EEPROM.write(slot + EEPROM_DRONE_GROS, mydrone->getGrosMode());
EEPROM.write(slot + EEPROM_BUZZ_GROS, mybuzz->getGrosMode());
EEPROM.write(slot + EEPROM_HI_MEL_CHAN, mystring->getChannel());
EEPROM.write(slot + EEPROM_LO_MEL_CHAN, mylowstring->getChannel());
EEPROM.write(slot + EEPROM_DRONE_CHAN, mydrone->getChannel());
EEPROM.write(slot + EEPROM_TROMP_CHAN, mytromp->getChannel());
EEPROM.write(slot + EEPROM_BUZZ_CHAN, mybuzz->getChannel());
EEPROM.write(slot + EEPROM_KEYCLICK_CHAN, mykeyclick->getChannel());

};

Expand Down
106 changes: 100 additions & 6 deletions tuning_screens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
/// @warning These functions are hardcoded to expect certain string objects to exist.
/// @{

/// @brief Prompts the user to choose between the primary tunining options: guided tuinings, manual tunings, volume control.
/// @brief Prompts the user to choose between the primary tunining options: guided tuinings, manual tunings, volume control, MIDI channel assignment.
/// @return True if an option was chosen, false otherwise.
bool tuning() {

bool done = false;
while (!done) {

if (use_solfege == 0) {
print_menu_4("Tuning Menu", "G/C, Guided", "D/G, Guided", "Manual Setup", "Volume Control");
print_menu_5("Tuning Menu", "G/C, Guided", "D/G, Guided", "Manual Setup", "Volume Control", "MIDI Channels");
} else if (use_solfege == 1) {
print_menu_4("Tuning Menu", "Sol/Do, Guided", "Re/Sol, Guided", "Manual Setup", "Volume Control");
print_menu_5("Tuning Menu", "Sol/Do, Guided", "Re/Sol, Guided", "Manual Setup", "Volume Control", "MIDI Channels");
} else {
print_menu_4("Tuning Menu", "G/C (Sol/Do), Guided", "D/G (Re/Sol), Guided", "Manual Setup", "Volume Control");
print_menu_5("Tuning Menu", "G/C (Sol/Do), Guided", "D/G (Re/Sol), Guided", "Manual Setup", "Volume Control", "MIDI Channels");
};
delay(150);

Expand All @@ -42,7 +42,9 @@ bool tuning() {
manual_tuning_screen();
} else if (my4Button->wasPressed()) {
volume_screen();
} else if (my5Button->wasPressed() || myXButton->wasPressed()) {
} else if (my5Button->wasPressed()) {
channel_screen();
} else if (myXButton->wasPressed()) {
return false;
} else if (my6Button->wasPressed()) {
cool_kids_screen();
Expand Down Expand Up @@ -413,6 +415,98 @@ void change_volume_screen(GurdyString *this_string) {
};
};

// This screen allows the user to make manual changes to each string's MIDI channel assignment.

/// @brief Promts the user to choose a string to change the MIDI channel of.
void channel_screen() {

while (true) {

print_menu_6("MIDI Channel",
String("Hi Melody - ") + mystring->getChannel(),
String("Low Melody - ") + mylowstring->getChannel(),
String("Trompette - ") + mytromp->getChannel(),
String("Drone - ") + mydrone->getChannel(),
String("Buzz - ") + mybuzz->getChannel(),
String("Key Click - ") + mykeyclick->getChannel());
delay(150);

// Check the 1 and 2 buttons
my1Button->update();
my2Button->update();
my3Button->update();
my4Button->update();
my5Button->update();
my6Button->update();
myXButton->update();

if (my1Button->wasPressed()) {
change_channel_screen(mystring);

} else if (my2Button->wasPressed()) {
change_channel_screen(mylowstring);

} else if (my3Button->wasPressed()) {
change_channel_screen(mytromp);

} else if (my4Button->wasPressed()) {
change_channel_screen(mydrone);

} else if (my5Button->wasPressed()) {
change_channel_screen(mybuzz);

} else if (my6Button->wasPressed()) {
change_channel_screen(mykeyclick);

} else if (myXButton->wasPressed()) {
return;
};
};

return;
};

/// @brief Prompts the user to adjust the volume of the given string.
/// @param this_string The GurdyString object to adjust the volume of
void change_channel_screen(GurdyString *this_string) {
bool done = false;
int new_cha = this_string->getChannel();
delay(300);
while (!done) {

print_value_selection("MIDI Channel - " + this_string->getName(), new_cha);

my1Button->update();
my2Button->update();
myXButton->update();

if (my1Button->wasPressed()) {
if (new_cha > 1) {
new_cha -= 1;
delay(300);
};
} else if (my1Button->beingPressed()) {
if (new_cha > 1) {
new_cha -= 1;
delay(100);
};
} else if (my2Button->wasPressed()) {
if (new_cha < 16) {
new_cha += 1;
delay(300);
};
} else if (my2Button->beingPressed()) {
if (new_cha < 16) {
new_cha += 1;
delay(100);
};
} else if (myXButton->wasPressed()) {
this_string->setChannel(new_cha);
done = true;
};
};
};

/// @brief Prompts the user to add additional tones to each string (and buzz).
/// @details This is a "hidden" feature.
void cool_kids_screen() {
Expand Down Expand Up @@ -477,4 +571,4 @@ void cool_kids_screen() {
};

return;
};
};
3 changes: 3 additions & 0 deletions tuning_screens.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ void tune_string_screen(GurdyString *this_string);
void volume_screen();
void change_volume_screen(GurdyString *this_string);

void channel_screen();
void change_channel_screen(GurdyString *this_string);

void cool_kids_screen();
#endif

0 comments on commit 039b46f

Please sign in to comment.