@@ -104,8 +104,6 @@ void GuiComponent::paint (juce::Graphics& g)
104
104
proportionOfWidth (0 .2f ), proportionOfHeight (0 .07f )), juce::Justification::centredLeft, false );
105
105
106
106
automateLabelText (&sampleRateText, (int ) audioProcessor.getSourceSampleRate (currentSample));
107
- automateLabelText (&resampleRateText, (int ) audioProcessor.getResampleRate (currentSample));
108
-
109
107
return ;
110
108
}
111
109
@@ -185,12 +183,12 @@ void GuiComponent::resized()
185
183
midiLowNote.setBoundsRelative (0 .595f , 0 .63f , 0 .035f , 0 .05f );
186
184
midiHiNote.setBoundsRelative (0 .635f , 0 .63f , 0 .035f , 0 .05f );
187
185
188
- startLoopText.setBoundsRelative (0 .1f , 0 .735f , 0 .07f , 0 .04f );
189
- endLoopText.setBoundsRelative (0 .1f , 0 .765f , 0 .07f , 0 .04f );
190
- replenLoopText.setBoundsRelative (0 .1f , 0 .795f , 0 .07f , 0 .04f );
186
+ startLoopText.setBoundsRelative (0 .1f , 0 .735f , 0 .08f , 0 .04f );
187
+ endLoopText.setBoundsRelative (0 .1f , 0 .765f , 0 .08f , 0 .04f );
188
+ replenLoopText.setBoundsRelative (0 .1f , 0 .795f , 0 .08f , 0 .04f );
191
189
192
- sampleRateText.setBoundsRelative (0 .62f , 0 .63f , 0 .07f , 0 .04f );
193
- resampleRateText.setBoundsRelative (0 .62f , 0 .67f , 0 .07f , 0 .04f );
190
+ sampleRateText.setBoundsRelative (0 .62f , 0 .63f , 0 .08f , 0 .04f );
191
+ resampleRateText.setBoundsRelative (0 .62f , 0 .67f , 0 .08f , 0 .04f );
194
192
195
193
decText.setBoundsRelative (0 .12f , 0 .51f , 0 .05f , 0 .03f );
196
194
hexText.setBoundsRelative (0 .17f , 0 .51f , 0 .05f , 0 .03f );
@@ -245,6 +243,9 @@ void GuiComponent::changeSampleChannel(const int &channel)
245
243
automateLabelText (&endLoopText, loopEnd);
246
244
automateLabelText (&replenLoopText, loopRpln);
247
245
246
+ automateLabelText (&sampleRateText, (int ) audioProcessor.getSourceSampleRate (currentSample));
247
+ automateLabelText (&resampleRateText, (int ) audioProcessor.getResampleRate (currentSample));
248
+
248
249
enableLoop.setToggleState (loopEnabled, juce::NotificationType::dontSendNotification);
249
250
enableLoop.setEnabled (loopEnabled);
250
251
@@ -329,6 +330,9 @@ void GuiComponent::buttonClicked(juce::Button *button)
329
330
automateLabelText (&endLoopText, loopEnd);
330
331
automateLabelText (&replenLoopText, loopEnd - loopStart);
331
332
333
+ automateLabelText (&sampleRateText, (int ) audioProcessor.getSourceSampleRate (currentSample));
334
+ automateLabelText (&resampleRateText, (int ) audioProcessor.getResampleRate (currentSample));
335
+
332
336
repaint ();
333
337
};
334
338
@@ -343,6 +347,9 @@ void GuiComponent::buttonClicked(juce::Button *button)
343
347
automateLabelText (&endLoopText, loopEnd);
344
348
automateLabelText (&replenLoopText, loopEnd - loopStart);
345
349
350
+ automateLabelText (&sampleRateText, (int ) audioProcessor.getSourceSampleRate (currentSample));
351
+ automateLabelText (&resampleRateText, (int ) audioProcessor.getResampleRate (currentSample));
352
+
346
353
repaint ();
347
354
};
348
355
@@ -406,6 +413,12 @@ void GuiComponent::parameterChanged(const juce::String ¶meterID, float newVa
406
413
automateLabelText (&replenLoopText, loopRpln);
407
414
}
408
415
416
+ if (parameterID.contains (" SAMPLE MIDI CHAN" + juce::String (currentSample)))
417
+ {
418
+ const juce::String channel = newValue <= 0 ? " ALL" : juce::String ((int ) (newValue + 1 ));
419
+ sampleMidiChannel.setText (channel, juce::NotificationType::dontSendNotification);
420
+ }
421
+
409
422
if (parameterID.contains (" SAMPLE ROOT NOTE" + juce::String (currentSample)))
410
423
{
411
424
const int midiNote = newValue < 0 ? 0 : newValue > 127 ? 127 : (int ) newValue;
@@ -481,65 +494,104 @@ void GuiComponent::initCheckBox(juce::Button *b, const juce::String &name, const
481
494
482
495
void GuiComponent::changeLoopText (juce::Label* l, const int type)
483
496
{
497
+ bool success = true ;
484
498
juce::String txt;
485
- int val = 0 ;
499
+ int val = - 1 ;
486
500
487
501
jassert (l != nullptr && type < 3 );
488
502
489
503
txt = l->getText ().toUpperCase ();
490
504
491
- if (txt.isEmpty ()) return ;
492
- if (!txt.containsOnly (" 0123456789ABCDEF" ) || (!textInHex && !txt.containsOnly (" 0123456789" ))) return ;
505
+ if (txt.isEmpty ())
506
+ success = false ;
507
+ else if (textIsHexValue (txt))
508
+ val = txt.getHexValue32 ();
509
+ else if (textIsDecValue (txt))
510
+ val = txt.getIntValue ();
511
+ else
512
+ success = false ;
493
513
494
- val = textInHex ? txt. getHexValue32 () : txt. getIntValue () ;
514
+ if ( val < 0 ) success = false ;
495
515
496
516
switch (type)
497
517
{
498
518
case 0 :
499
519
500
- if (val < 0 ) return ;
501
- if (val >= audioProcessor. getLoopEnd (currentSample)) return ;
520
+ if (val >= audioProcessor. getLoopEnd (currentSample))
521
+ success = false ;
502
522
503
- audioProcessor.setLoopStart (currentSample, val);
523
+ if (success) audioProcessor.setLoopStart (currentSample, val);
524
+ else val = audioProcessor.getLoopStart (currentSample);
504
525
505
526
break ;
506
527
507
528
case 1 :
508
529
509
- val += textInHex ? startLoopText.getText ().getHexValue32 () : startLoopText.getText ().getIntValue ();
530
+ if (!success)
531
+ {
532
+ val = audioProcessor.getLoopEnd (currentSample) - audioProcessor.getLoopStart (currentSample);
533
+ break ;
534
+ }
535
+
536
+ val += audioProcessor.getLoopStart (currentSample);
510
537
[[fallthrough]];
511
538
512
539
case 2 :
513
540
514
- if (val <= audioProcessor.getLoopStart (currentSample)) return ;
515
- if (val > audioProcessor. getWaveForm (currentSample). getNumSamples ()) return ;
541
+ if (val <= audioProcessor.getLoopStart (currentSample) || val > audioProcessor. getWaveForm (currentSample). getNumSamples ())
542
+ success = false ;
516
543
517
- audioProcessor.setLoopEnd (currentSample, val);
544
+ if (success) audioProcessor.setLoopEnd (currentSample, val);
545
+ else val = audioProcessor.getLoopEnd (currentSample);
518
546
519
547
break ;
520
548
}
521
-
522
- l->setText (txt.paddedLeft (' 0' , 6 ), juce::NotificationType::dontSendNotification);
549
+
550
+ if (type == 1 ) val = audioProcessor.getLoopEnd (currentSample) - audioProcessor.getLoopStart (currentSample);
551
+
552
+ txt = textInHex ? juce::String::toHexString (val).toUpperCase () : juce::String (val);
553
+ l->setText (txt.paddedLeft (' 0' , 8 ), juce::NotificationType::dontSendNotification);
523
554
}
524
555
525
- void GuiComponent::changeRateText (juce::Label *l)
556
+ void GuiComponent::changeRateText (juce::Label *l, const int type )
526
557
{
558
+ bool success = true ;
527
559
juce::String txt;
528
560
int val = 0 ;
529
561
530
- jassert (l != nullptr );
562
+ jassert (l != nullptr && type < 2 );
531
563
532
564
txt = l->getText ().toUpperCase ();
533
565
534
- if (txt.isEmpty ()) return ;
535
- if (!txt.containsOnly (" 0123456789ABCDEF" ) /* || (!textInHex && !txt.contains("0123456789")) */ ) return ;
566
+ if (txt.isEmpty ())
567
+ success = false ;
568
+ else if (textIsHexValue (txt))
569
+ val = txt.getHexValue32 ();
570
+ else if (textIsDecValue (txt))
571
+ val = txt.getIntValue ();
572
+ else
573
+ success = false ;
574
+
575
+ if (val < 1000 || val >= 1000000 ) success = false ;
536
576
537
- val = textInHex ? txt.getHexValue32 () : txt.getIntValue ();
577
+ switch (type)
578
+ {
579
+ case 0 :
580
+
581
+ if (success) audioProcessor.setSourceSampleRate (currentSample, val);
582
+ else val = audioProcessor.getSourceSampleRate (currentSample);
583
+
584
+ break ;
538
585
539
- if (val <= 0 ) return ;
540
- if (val >= 1000000 ) return ;
586
+ case 1 :
587
+
588
+ if (success) audioProcessor.setResampleRate (currentSample, val);
589
+ else val = audioProcessor.getResampleRate (currentSample);
590
+
591
+ break ;
592
+ }
541
593
542
- audioProcessor. setSourceSampleRate (currentSample, val);
594
+ txt = textInHex ? juce::String::toHexString (val). toUpperCase () : juce::String ( val);
543
595
l->setText (txt.paddedLeft (' 0' , 6 ), juce::NotificationType::dontSendNotification);
544
596
}
545
597
@@ -555,7 +607,7 @@ void GuiComponent::changeMidiNoteText(juce::Label *l, const int type)
555
607
556
608
if (txt.isEmpty ()) success = false ;
557
609
558
- else if (!textInHex && txt. containsOnly ( " 0123456789 " ))
610
+ else if (textIsDecValue (txt ))
559
611
{
560
612
note = txt.getIntValue ();
561
613
}
@@ -601,58 +653,52 @@ void GuiComponent::changeMidiNoteText(juce::Label *l, const int type)
601
653
void GuiComponent::initAllLabels ()
602
654
{
603
655
initLabel (&startLoopText,true );
604
- startLoopText.setText (" 000000 " , juce::NotificationType::dontSendNotification);
656
+ startLoopText.setText (" 00000000 " , juce::NotificationType::dontSendNotification);
605
657
startLoopText.onTextChange = [&] { changeLoopText (&startLoopText, 0 ); };
606
658
607
659
initLabel (&endLoopText,true );
608
- endLoopText.setText (" 000000 " , juce::NotificationType::dontSendNotification);
660
+ endLoopText.setText (" 00000000 " , juce::NotificationType::dontSendNotification);
609
661
endLoopText.onTextChange = [&] { changeLoopText (&endLoopText, 2 ); };
610
662
611
663
initLabel (&replenLoopText,true );
612
- replenLoopText.setText (" 000000 " , juce::NotificationType::dontSendNotification);
664
+ replenLoopText.setText (" 00000000 " , juce::NotificationType::dontSendNotification);
613
665
replenLoopText.onTextChange = [&] { changeLoopText (&replenLoopText, 1 ); };
614
666
615
667
initLabel (&sampleRateText,true );
616
- sampleRateText.setText (" 000000 " , juce::NotificationType::dontSendNotification);
617
- sampleRateText.onTextChange = [&] { changeRateText (&sampleRateText); };
668
+ sampleRateText.setText (" 00000000 " , juce::NotificationType::dontSendNotification);
669
+ sampleRateText.onTextChange = [&] { changeRateText (&sampleRateText, 0 ); };
618
670
sampleRateText.setVisible (false );
619
671
620
672
initLabel (&resampleRateText,true );
621
- resampleRateText.setText (" 000000" , juce::NotificationType::dontSendNotification);
622
- resampleRateText.onTextChange = [&]
623
- {
624
- double val = 0.0 ;
625
- const juce::String txt = resampleRateText.getText ().toUpperCase ();
626
-
627
- if (txt.isEmpty ()) return ;
628
- if (!txt.containsOnly (" 0123456789ABCDEF" ) || (!textInHex && !txt.containsOnly (" 0123456789" ))) return ;
629
-
630
- val = textInHex ? txt.getHexValue32 () : txt.getIntValue ();
631
-
632
- if (val <= 0 ) return ;
633
-
634
- audioProcessor.setResampleRate (currentSample, val);
635
- resampleRateText.setText (txt.paddedLeft (' 0' , 6 ), juce::NotificationType::dontSendNotification);
636
- };
637
-
673
+ resampleRateText.setText (" 00000000" , juce::NotificationType::dontSendNotification);
674
+ resampleRateText.onTextChange = [&] { changeRateText (&resampleRateText, 1 ); };
638
675
resampleRateText.setVisible (false );
639
676
640
677
initLabel (&sampleMidiChannel, false );
641
678
sampleMidiChannel.onTextChange = [&]
642
679
{
643
- if (sampleMidiChannel.getText ().isEmpty ()) return ;
680
+ juce::String chanText = sampleMidiChannel.getText ();
681
+ bool success = true ;
682
+ int channel = -1 ;
683
+
684
+ if (sampleMidiChannel.getText ().isEmpty ())
685
+ success = false ;
686
+ else if (textIsHexValue (chanText))
687
+ channel = chanText.getHexValue32 ();
688
+ else if (textIsDecValue (chanText))
689
+ channel = chanText.getIntValue ();
690
+ else if (chanText.compareIgnoreCase (" ALL" ) == 0 )
691
+ channel = 0 ;
692
+ else
693
+ success = false ;
644
694
645
- if (sampleMidiChannel.getText ().containsOnly (" 0123456789" ))
646
- {
647
- const int channel = sampleMidiChannel.getText ().getIntValue ();
695
+ if (channel < 0 || channel > 16 ) success = false ;
648
696
649
- if (channel < 0 ) return ;
650
- if ( channel > 16 ) return ;
697
+ if (success) audioProcessor. setMidiChannel (currentSample, channel) ;
698
+ else channel = audioProcessor. getMidiChannel (currentSample) ;
651
699
652
- audioProcessor.setMidiChannel (currentSample, channel);
653
- }
654
- else if (sampleMidiChannel.getText ().compareIgnoreCase (" ALL" ) == 0 )
655
- audioProcessor.setMidiChannel (currentSample, 0 );
700
+ chanText = channel == 0 ? " ALL" : juce::String (channel).paddedLeft (' 0' , 2 );
701
+ sampleMidiChannel.setText (chanText, juce::NotificationType::dontSendNotification);
656
702
};
657
703
658
704
initLabel (&midiRootNote, false );
@@ -713,20 +759,13 @@ void GuiComponent::initAllCheckboxes()
713
759
714
760
void GuiComponent::automateLabelText (juce::Label *l, const int value)
715
761
{
716
- const juce::String valueText = textInHex ? juce::String::toHexString (value) : juce::String (value);
762
+ const juce::String valueText = textInHex ? juce::String::toHexString (value). toUpperCase () : juce::String (value);
717
763
718
764
jassert (l != nullptr );
719
765
720
- if (l->isBeingEdited ())
721
- {
722
- l->getCurrentTextEditor ()->setColour (juce::TextEditor::highlightColourId, JPAL (AMI_ORG));
723
- l->getCurrentTextEditor ()->setJustification (juce::Justification::centred);
724
- return ;
725
- }
726
-
727
766
if ((textInHex && (l->getText ().getHexValue32 () == value)) || (!textInHex && (l->getText ().getIntValue () == value))) return ;
728
767
729
- l->setText (valueText.paddedLeft (' 0' , 6 ).toUpperCase (), juce::NotificationType::dontSendNotification);
768
+ l->setText (valueText.paddedLeft (' 0' , 8 ).toUpperCase (), juce::NotificationType::dontSendNotification);
730
769
}
731
770
732
771
void GuiComponent::hideMainOptions ()
@@ -763,3 +802,13 @@ void GuiComponent::hideMoreOptions()
763
802
forwardLoop.setVisible (showExtendedOptions);
764
803
pingpongLoop.setVisible (showExtendedOptions);
765
804
}
805
+
806
+ bool GuiComponent::textIsHexValue (const juce::String &value)
807
+ {
808
+ return !textInHex ? false : value.toLowerCase ().containsOnly (" 0123456789abcdef" );
809
+ }
810
+
811
+ bool GuiComponent::textIsDecValue (const juce::String &value)
812
+ {
813
+ return textInHex ? false : value.containsOnly (" 0123456789" );
814
+ }
0 commit comments