Skip to content

Commit cc42251

Browse files
committed
fixed midi mapping bug, added hex value for key number midi mapping
1 parent 157822c commit cc42251

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

Source/GuiComponent.cpp

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ void GuiComponent::changeSampleChannel(const int &channel)
257257
if (midiChannel > 0) sampleMidiChannel.setText(juce::String(midiChannel).paddedLeft('0', 2), juce::NotificationType::dontSendNotification);
258258
else sampleMidiChannel.setText("ALL", juce::NotificationType::dontSendNotification);
259259

260-
midiRootNote.setText(notes[audioProcessor.getRootNote(currentSample)], juce::NotificationType::dontSendNotification);
261-
midiLowNote.setText(notes[audioProcessor.getLowNote(currentSample)], juce::NotificationType::dontSendNotification);
262-
midiHiNote.setText(notes[audioProcessor.getHighNote(currentSample)], juce::NotificationType::dontSendNotification);
260+
midiRootNote.setText(notes.operator[](audioProcessor.getRootNote(currentSample)), juce::NotificationType::dontSendNotification);
261+
midiLowNote.setText(notes.operator[](audioProcessor.getLowNote(currentSample)), juce::NotificationType::dontSendNotification);
262+
midiHiNote.setText(notes.operator[](audioProcessor.getHighNote(currentSample)), juce::NotificationType::dontSendNotification);
263263

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

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

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

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

546546
void GuiComponent::changeMidiNoteText(juce::Label *l, const int type)
547547
{
548+
bool success = true;
548549
juce::String txt;
549-
int note = 0;
550+
int note = -1;
550551

551552
jassert(l != nullptr);
552553

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

555-
if (txt.isEmpty()) return;
556+
if (txt.isEmpty()) success = false;
556557

557-
if (txt.containsOnly("0123456789"))
558+
else if (!textInHex && txt.containsOnly("0123456789"))
558559
{
559560
note = txt.getIntValue();
560561
}
561562
else if (txt.containsOnly("0123456789ABCDEFG-#"))
562563
{
563-
for (int i = 0; i < 128; i++)
564-
{
565-
if (notes[i].compare(txt) == 0)
566-
{
567-
note = i;
568-
break;
569-
}
570-
}
564+
// notes will always have letter or - as first character, hex value of note will always have letter as second character
565+
if(std::isalpha(txt.operator[](0)) || txt.operator[](0) == '-')
566+
note = notes.indexOf(txt);
567+
else
568+
note = txt.getHexValue32();
569+
}
570+
else
571+
{
572+
success = false;
571573
}
572574

573-
if (note < 0 || note > 127) return;
575+
if (note < 0 || note > 127) success = false;
574576

575577
switch (type)
576578
{
577579
case 0:
578580

579-
audioProcessor.setRootNote(currentSample, note);
581+
if(success) audioProcessor.setRootNote(currentSample, note);
582+
else note = audioProcessor.getRootNote(currentSample);
580583
break;
581584

582585
case 1:
583586

584-
audioProcessor.setLowNote(currentSample, note);
587+
if(success) audioProcessor.setLowNote(currentSample, note);
588+
else note = audioProcessor.getLowNote(currentSample);
585589
break;
586590

587591
case 2:
588592

589-
audioProcessor.setHighNote(currentSample, note);
593+
if(success) audioProcessor.setHighNote(currentSample, note);
594+
note = audioProcessor.getHighNote(currentSample);
590595
break;
591596
}
597+
598+
l->setText(notes.operator[](note), juce::NotificationType::dontSendNotification);
592599
}
593600

594601
void GuiComponent::initAllLabels()

Source/GuiComponent.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class GuiComponent : public juce::Component,
7373

7474
SliderComponent handleSliders;
7575

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

0 commit comments

Comments
 (0)