Skip to content

Commit

Permalink
fixed midi mapping bug, added hex value for key number midi mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
astriiddev committed May 1, 2024
1 parent 157822c commit cc42251
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
49 changes: 28 additions & 21 deletions Source/GuiComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ void GuiComponent::changeSampleChannel(const int &channel)
if (midiChannel > 0) sampleMidiChannel.setText(juce::String(midiChannel).paddedLeft('0', 2), juce::NotificationType::dontSendNotification);
else sampleMidiChannel.setText("ALL", juce::NotificationType::dontSendNotification);

midiRootNote.setText(notes[audioProcessor.getRootNote(currentSample)], juce::NotificationType::dontSendNotification);
midiLowNote.setText(notes[audioProcessor.getLowNote(currentSample)], juce::NotificationType::dontSendNotification);
midiHiNote.setText(notes[audioProcessor.getHighNote(currentSample)], juce::NotificationType::dontSendNotification);
midiRootNote.setText(notes.operator[](audioProcessor.getRootNote(currentSample)), juce::NotificationType::dontSendNotification);
midiLowNote.setText(notes.operator[](audioProcessor.getLowNote(currentSample)), juce::NotificationType::dontSendNotification);
midiHiNote.setText(notes.operator[](audioProcessor.getHighNote(currentSample)), juce::NotificationType::dontSendNotification);

if(audioProcessor.getPingPongLoop(currentSample))
{
Expand Down Expand Up @@ -409,19 +409,19 @@ void GuiComponent::parameterChanged(const juce::String &parameterID, float newVa
if (parameterID.contains("SAMPLE ROOT NOTE" + juce::String(currentSample)))
{
const int midiNote = newValue < 0 ? 0 : newValue > 127 ? 127 : (int) newValue;
midiRootNote.setText(notes[midiNote], juce::NotificationType::dontSendNotification);
midiRootNote.setText(notes.operator[](midiNote), juce::NotificationType::dontSendNotification);
}

if (parameterID.contains("SAMPLE LOW NOTE" + juce::String(currentSample)))
{
const int midiNote = newValue < 0 ? 0 : newValue > 127 ? 127 : (int) newValue;
midiHiNote.setText(notes[midiNote], juce::NotificationType::dontSendNotification);
midiLowNote.setText(notes.operator[](midiNote), juce::NotificationType::dontSendNotification);
}

if (parameterID.contains("SAMPLE HIGH NOTE" + juce::String(currentSample)))
{
const int midiNote = newValue < 0 ? 0 : newValue > 127 ? 127 : (int) newValue;
midiRootNote.setText(notes[midiNote], juce::NotificationType::dontSendNotification);
midiHiNote.setText(notes.operator[](midiNote), juce::NotificationType::dontSendNotification);
}
}

Expand Down Expand Up @@ -545,50 +545,57 @@ void GuiComponent::changeRateText(juce::Label *l)

void GuiComponent::changeMidiNoteText(juce::Label *l, const int type)
{
bool success = true;
juce::String txt;
int note = 0;
int note = -1;

jassert(l != nullptr);

txt = l->getText().toUpperCase();

if (txt.isEmpty()) return;
if (txt.isEmpty()) success = false;

if (txt.containsOnly("0123456789"))
else if (!textInHex && txt.containsOnly("0123456789"))
{
note = txt.getIntValue();
}
else if (txt.containsOnly("0123456789ABCDEFG-#"))
{
for (int i = 0; i < 128; i++)
{
if (notes[i].compare(txt) == 0)
{
note = i;
break;
}
}
// notes will always have letter or - as first character, hex value of note will always have letter as second character
if(std::isalpha(txt.operator[](0)) || txt.operator[](0) == '-')
note = notes.indexOf(txt);
else
note = txt.getHexValue32();
}
else
{
success = false;
}

if (note < 0 || note > 127) return;
if (note < 0 || note > 127) success = false;

switch (type)
{
case 0:

audioProcessor.setRootNote(currentSample, note);
if(success) audioProcessor.setRootNote(currentSample, note);
else note = audioProcessor.getRootNote(currentSample);
break;

case 1:

audioProcessor.setLowNote(currentSample, note);
if(success) audioProcessor.setLowNote(currentSample, note);
else note = audioProcessor.getLowNote(currentSample);
break;

case 2:

audioProcessor.setHighNote(currentSample, note);
if(success) audioProcessor.setHighNote(currentSample, note);
note = audioProcessor.getHighNote(currentSample);
break;
}

l->setText(notes.operator[](note), juce::NotificationType::dontSendNotification);
}

void GuiComponent::initAllLabels()
Expand Down
2 changes: 1 addition & 1 deletion Source/GuiComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class GuiComponent : public juce::Component,

SliderComponent handleSliders;

juce::String notes[128] = { "-C2", "-C#2", "-D2", "-D#2", "-E2", "-F2", "-F#2", "-G2",
juce::StringArray notes = { "-C2", "-C#2", "-D2", "-D#2", "-E2", "-F2", "-F#2", "-G2",
"-G#2", "-A2", "-A#2", "-B2", "-C1", "-C#1", "-D1", "-D#1",
"-E1", "-F1", "-F#1", "-G1", "-G#1", "-A1", "-A#1", "-B1",
"C0", "C#0", "D0", "D#0", "E0", "F0", "F#0", "G0",
Expand Down

0 comments on commit cc42251

Please sign in to comment.