/* ============================================================================== This is an automatically generated file created by the Jucer! Creation date: 19 Aug 2012 10:54:59am Be careful when adding custom code to these files, as only the code within the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded and re-saved. Jucer version: 1.12 ------------------------------------------------------------------------------ The Jucer is part of the JUCE library - "Jules' Utility Class Extensions" Copyright 2004-6 by Raw Material Software ltd. ============================================================================== */ //[Headers] You can add your own extra header files here... #include "synth/param_scale.h" //[/Headers] #include "MidiCC_PopUp.h" //[MiscUserDefs] You can add your own user definitions and misc code here... //[/MiscUserDefs] //============================================================================== MidiCC_PopUp::MidiCC_PopUp (JaySynthMidiCC *pMidiCC, int paramID, synth_float_t currParamValue, JaySynth::midiCC_info_t *pCurrMidiCCinfo, String name, MidiCC_PopUp_Listener *listener) : Component (L"MidiCC PopUp"), textButton_OK (0), label_MidiCC_ID (0), label_control_min (0), label_control_max (0), slider_test (0), button_move_sliders_enable (0), button_assign_enable (0), button_midi_learn (0), label_parameter_name (0), button_apply_on_patch_init (0) { addAndMakeVisible (textButton_OK = new TextButton (L"OK")); textButton_OK->addListener (this); addAndMakeVisible (label_MidiCC_ID = new Label (L"MidiCC ID", L"0")); label_MidiCC_ID->setTooltip (L"This is the Midi-Controller Number"); label_MidiCC_ID->setFont (Font (15.0000f, Font::plain)); label_MidiCC_ID->setJustificationType (Justification::centredRight); label_MidiCC_ID->setEditable (true, true, false); label_MidiCC_ID->setColour (Label::textColourId, Colours::white); label_MidiCC_ID->setColour (TextEditor::textColourId, Colours::black); label_MidiCC_ID->setColour (TextEditor::backgroundColourId, Colour (0x0)); label_MidiCC_ID->setColour (TextEditor::highlightColourId, Colours::yellow); label_MidiCC_ID->addListener (this); addAndMakeVisible (label_control_min = new Label (L"Control Min", L"0")); label_control_min->setTooltip (L"Parameter minimum value"); label_control_min->setFont (Font (15.0000f, Font::plain)); label_control_min->setJustificationType (Justification::centredRight); label_control_min->setEditable (true, true, false); label_control_min->setColour (Label::textColourId, Colours::white); label_control_min->setColour (TextEditor::textColourId, Colours::black); label_control_min->setColour (TextEditor::backgroundColourId, Colour (0x0)); label_control_min->setColour (TextEditor::highlightColourId, Colours::yellow); label_control_min->addListener (this); addAndMakeVisible (label_control_max = new Label (L"Control Max", L"0")); label_control_max->setTooltip (L"Parameter maximum value"); label_control_max->setFont (Font (15.0000f, Font::plain)); label_control_max->setJustificationType (Justification::centredRight); label_control_max->setEditable (true, true, false); label_control_max->setColour (Label::textColourId, Colours::white); label_control_max->setColour (TextEditor::textColourId, Colours::black); label_control_max->setColour (TextEditor::backgroundColourId, Colour (0x0)); label_control_max->setColour (TextEditor::highlightColourId, Colours::yellow); label_control_max->addListener (this); addAndMakeVisible (slider_test = new Slider (L"Test Slider")); slider_test->setTooltip (L"Test Slider"); slider_test->setRange (0, 1, 0); slider_test->setSliderStyle (Slider::LinearHorizontal); slider_test->setTextBoxStyle (Slider::NoTextBox, true, 80, 20); slider_test->addListener (this); addAndMakeVisible (button_move_sliders_enable = new ToggleButton (L"MoveParams Enable")); button_move_sliders_enable->setTooltip (L"If \'Absolute = no\', the parameter is alterered relatively from the given slider position on the main window in the specified range. If \'\'Absolute = yes\', the midi controller alters parameter absolutely in the specified range. In this mode sliders really move on the main window."); button_move_sliders_enable->setButtonText (String::empty); button_move_sliders_enable->addListener (this); addAndMakeVisible (button_assign_enable = new ToggleButton (L"Assign Enable")); button_assign_enable->setTooltip (L"Set this to make MIDI-Controller assignment active"); button_assign_enable->setButtonText (String::empty); button_assign_enable->addListener (this); addAndMakeVisible (button_midi_learn = new ToggleButton (L"Midi Learn Button")); button_midi_learn->setTooltip (L"Set this to learn MIDI-Controller number from MIDI-controller movement"); button_midi_learn->setButtonText (String::empty); button_midi_learn->addListener (this); button_midi_learn->setColour (ToggleButton::textColourId, Colours::white); addAndMakeVisible (label_parameter_name = new Label (L"Parameter Name", L"Parameter Name")); label_parameter_name->setFont (Font (20.0000f, Font::plain)); label_parameter_name->setJustificationType (Justification::centred); label_parameter_name->setEditable (false, false, false); label_parameter_name->setColour (Label::textColourId, Colours::white); label_parameter_name->setColour (TextEditor::textColourId, Colours::black); label_parameter_name->setColour (TextEditor::backgroundColourId, Colour (0x0)); addAndMakeVisible (button_apply_on_patch_init = new ToggleButton (L"Apply on Patch Init Enable")); button_apply_on_patch_init->setTooltip (L"Set this to apply current Midi-Controller position on initialization of this patch (e.g. Program change)"); button_apply_on_patch_init->setButtonText (String::empty); button_apply_on_patch_init->addListener (this); //[UserPreSize] //[/UserPreSize] setSize (248, 280); //[Constructor] You can add your own custom stuff here.. this->pMidiCC = pMidiCC; pSavedMidiCCinfo = pCurrMidiCCinfo; pMidiCC_container = pMidiCC->getAtParamID(paramID); savedParamValue = currParamValue; lastMidiCCvalue = pSavedMidiCCinfo[pMidiCC->getControllerID(pMidiCC_container)].value; this->currentParamValue = savedParamValue; this->currentControlValue = 0; if (isEnabled()) { this->currentParamValue = toParam(pMidiCC->getParam(pMidiCC_container), (synth_float_t)lastMidiCCvalue); this->currentControlValue = toParam(pMidiCC->getControl(pMidiCC_container), (synth_float_t)lastMidiCCvalue); } lastParamValue = this->currentParamValue; lastControlValue = this->currentControlValue; GetMin(); GetMax(); restoreTestSlider(); label_MidiCC_ID->setText(String(pMidiCC->getControllerID(pMidiCC_container)), juce::NotificationType::dontSendNotification); label_parameter_name->setText(name, juce::NotificationType::dontSendNotification); button_assign_enable->setToggleState(pMidiCC->isAssigned(pMidiCC_container), juce::NotificationType::dontSendNotification); button_move_sliders_enable->setToggleState(pMidiCC->doChangeParameter(pMidiCC_container), juce::NotificationType::dontSendNotification); button_apply_on_patch_init->setToggleState(pMidiCC->doApplyOnPatchInit(pMidiCC_container), juce::NotificationType::dontSendNotification); button_assign_enable->setTriggeredOnMouseDown (true); button_assign_enable->setClickingTogglesState(true); button_move_sliders_enable->setTriggeredOnMouseDown (true); button_move_sliders_enable->setClickingTogglesState(true); button_midi_learn->setTriggeredOnMouseDown (true); button_midi_learn->setClickingTogglesState(true); button_apply_on_patch_init->setTriggeredOnMouseDown (true); button_apply_on_patch_init->setClickingTogglesState(true); addListener(listener); listeners.call (&MidiCC_PopUp_Listener::MidiCC_PopUp_event, POPUP_CREATED); //[/Constructor] } MidiCC_PopUp::~MidiCC_PopUp() { //[Destructor_pre]. You can add your own custom destruction code here.. //[/Destructor_pre] deleteAndZero (textButton_OK); deleteAndZero (label_MidiCC_ID); deleteAndZero (label_control_min); deleteAndZero (label_control_max); deleteAndZero (slider_test); deleteAndZero (button_move_sliders_enable); deleteAndZero (button_assign_enable); deleteAndZero (button_midi_learn); deleteAndZero (label_parameter_name); deleteAndZero (button_apply_on_patch_init); //[Destructor]. You can add your own custom destruction code here.. //[/Destructor] } //============================================================================== void MidiCC_PopUp::paint (Graphics& g) { //[UserPrePaint] Add your own custom painting code here.. //[/UserPrePaint] g.setColour (Colour (0xff2a64a5)); g.fillRoundedRectangle (0.0f, 4.0f, 244.0f, 274.0f, 10.0000f); g.setColour (Colours::white); g.drawRoundedRectangle (2.0f, 3.0f, 243.0f, 274.0f, 7.0000f, 4.0000f); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Midi Controller", 16, 122, 94, 20, Justification::centredLeft, true); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Active", 16, 48, 62, 20, Justification::centredLeft, true); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Absolute", 16, 68, 59, 20, Justification::centredLeft, true); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Minimum", 16, 142, 75, 20, Justification::centredLeft, true); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Maximum", 16, 162, 75, 20, Justification::centredLeft, true); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Test it", 18, 194, 46, 20, Justification::centredLeft, true); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Learn", 192, 122, 38, 20, Justification::centredLeft, true); g.setColour (Colours::white); g.setFont (Font (15.0000f, Font::plain)); g.drawText (L"Apply on patch init", 16, 88, 120, 20, Justification::centredLeft, true); //[UserPaint] Add your own custom painting code here.. //[/UserPaint] } void MidiCC_PopUp::resized() { textButton_OK->setBounds (22, 238, 202, 22); label_MidiCC_ID->setBounds (135, 122, 32, 20); label_control_min->setBounds (103, 144, 64, 20); label_control_max->setBounds (103, 166, 64, 20); slider_test->setBounds (64, 192, 168, 26); button_move_sliders_enable->setBounds (148, 68, 20, 20); button_assign_enable->setBounds (148, 48, 20, 20); button_midi_learn->setBounds (172, 122, 20, 20); label_parameter_name->setBounds (12, 12, 212, 24); button_apply_on_patch_init->setBounds (148, 88, 20, 20); //[UserResized] Add your own custom resize handling here.. //[/UserResized] } void MidiCC_PopUp::buttonClicked (Button* buttonThatWasClicked) { //[UserbuttonClicked_Pre] bool state; //[/UserbuttonClicked_Pre] if (buttonThatWasClicked == textButton_OK) { //[UserButtonCode_textButton_OK] -- add your button handler code here.. currentControlValue = 0; if (isEnabled() && !doChangeParameter()) currentControlValue = toParam(pMidiCC->getControl(pMidiCC_container), (synth_float_t)lastMidiCCvalue); currentParamValue = savedParamValue; if (isEnabled() && doChangeParameter()) currentParamValue = toParam(pMidiCC->getParam(pMidiCC_container), (synth_float_t)lastMidiCCvalue); listeners.call (&MidiCC_PopUp_Listener::MidiCC_PopUp_event, POPUP_OK); //[/UserButtonCode_textButton_OK] } else if (buttonThatWasClicked == button_move_sliders_enable) { //[UserButtonCode_button_move_sliders_enable] -- add your button handler code here.. state = buttonThatWasClicked->getToggleState(); pMidiCC->setDoChangeParameter(pMidiCC_container, state); if (state) { currentParamValue = lastParamValue; lastControlValue = currentControlValue; } else { currentControlValue = lastControlValue; lastParamValue = currentParamValue; } GetMin(); GetMax(); restoreTestSlider(); TestValueUpdate(); //[/UserButtonCode_button_move_sliders_enable] } else if (buttonThatWasClicked == button_assign_enable) { //[UserButtonCode_button_assign_enable] -- add your button handler code here.. if (buttonThatWasClicked->getToggleState()) pMidiCC->add(pMidiCC_container, label_MidiCC_ID->getText().getIntValue()); else pMidiCC->remove(pMidiCC_container, label_MidiCC_ID->getText().getIntValue()); if (isEnabled()) { currentParamValue = toParam(pMidiCC->getParam(pMidiCC_container), (synth_float_t)lastMidiCCvalue); currentControlValue = toParam(pMidiCC->getControl(pMidiCC_container), (synth_float_t)lastMidiCCvalue); } restoreTestSlider(); TestValueUpdate(); //[/UserButtonCode_button_assign_enable] } else if (buttonThatWasClicked == button_midi_learn) { //[UserButtonCode_button_midi_learn] -- add your button handler code here.. //[/UserButtonCode_button_midi_learn] } else if (buttonThatWasClicked == button_apply_on_patch_init) { //[UserButtonCode_button_apply_on_patch_init] -- add your button handler code here.. state = buttonThatWasClicked->getToggleState(); pMidiCC->setDoApplyOnPatchInit(pMidiCC_container, state); restoreTestSlider(); TestValueUpdate(); //[/UserButtonCode_button_apply_on_patch_init] } //[UserbuttonClicked_Post] //[/UserbuttonClicked_Post] } void MidiCC_PopUp::labelTextChanged (Label* labelThatHasChanged) { //[UserlabelTextChanged_Pre] //[/UserlabelTextChanged_Pre] if (labelThatHasChanged == label_MidiCC_ID) { //[UserLabelCode_label_MidiCC_ID] -- add your label text handling code here.. pMidiCC->setControllerID(pMidiCC_container, label_MidiCC_ID->getText().getIntValue()); label_MidiCC_ID->setText(String(pMidiCC->getControllerID(pMidiCC_container)), juce::NotificationType::dontSendNotification); button_midi_learn->setToggleState(false, juce::NotificationType::dontSendNotification); lastMidiCCvalue = pSavedMidiCCinfo[pMidiCC->getControllerID(pMidiCC_container)].value; if (isEnabled()) { currentParamValue = toParam(pMidiCC->getParam(pMidiCC_container), (synth_float_t)lastMidiCCvalue); currentControlValue = toParam(pMidiCC->getControl(pMidiCC_container), (synth_float_t)lastMidiCCvalue); } restoreTestSlider(); TestValueUpdate(); //[/UserLabelCode_label_MidiCC_ID] } else if (labelThatHasChanged == label_control_min) { //[UserLabelCode_label_control_min] -- add your label text handling code here.. SetMin(); restoreTestSlider(); TestValueUpdate(); //[/UserLabelCode_label_control_min] } else if (labelThatHasChanged == label_control_max) { //[UserLabelCode_label_control_max] -- add your label text handling code here.. SetMax(); restoreTestSlider(); TestValueUpdate(); //[/UserLabelCode_label_control_max] } //[UserlabelTextChanged_Post] //[/UserlabelTextChanged_Post] } void MidiCC_PopUp::sliderValueChanged (Slider* sliderThatWasMoved) { //[UsersliderValueChanged_Pre] //[/UsersliderValueChanged_Pre] if (sliderThatWasMoved == slider_test) { //[UserSliderCode_slider_test] -- add your slider handling code here.. if (doChangeParameter()) { slider_test->setTooltip (String(toParam(pMidiCC->getParam(pMidiCC_container), (synth_float_t)slider_test->getValue()))); } else { if (lastControlValue == 0) slider_test->setTooltip (L"0.0"); else slider_test->setTooltip (String(toParam(pMidiCC->getControl(pMidiCC_container), (synth_float_t)slider_test->getValue()))); } TestValueUpdate(); //[/UserSliderCode_slider_test] } //[UsersliderValueChanged_Post] //[/UsersliderValueChanged_Post] } //[MiscUserCode] You can add your own definitions of your custom methods or any other code here... void MidiCC_PopUp::mouseWheelMove(const MouseEvent &/*event*/, const MouseWheelDetails &/*wheel*/) { } void MidiCC_PopUp::GetMin() { if (doChangeParameter()) { label_control_min->setText(String(pMidiCC->getParamMin(pMidiCC_container)), juce::NotificationType::dontSendNotification); } else { label_control_min->setText(String(pMidiCC->getControlMin(pMidiCC_container)), juce::NotificationType::dontSendNotification); } } void MidiCC_PopUp::GetMax() { if (doChangeParameter()) { label_control_max->setText(String(pMidiCC->getParamMax(pMidiCC_container)), juce::NotificationType::dontSendNotification); } else { label_control_max->setText(String(pMidiCC->getControlMax(pMidiCC_container)), juce::NotificationType::dontSendNotification); } } void MidiCC_PopUp::SetMin() { synth_float_t value; param_info_t *pConstraints = pMidiCC->getConstraints(pMidiCC_container); param_info_t *pInfo = NULL; value = (synth_float_t)label_control_min->getText().getFloatValue(); while (doChangeParameter()) { pInfo = pMidiCC->getParam(pMidiCC_container); if (value < pConstraints->pmin) value = pConstraints->pmin; if (value > pInfo->pmax) value = pInfo->pmax; // Min == Max => crash if (value == pMidiCC->getParamMax(pMidiCC_container)) break; pMidiCC->setParamMin(pMidiCC_container, value); break; } while (!doChangeParameter()) { pInfo = pMidiCC->getControl(pMidiCC_container); if (fabs(value) > fabs(pConstraints->pmax)) value = pConstraints->pmax*fabs(value)/value; // Min == Max => crash if (value == pMidiCC->getControlMax(pMidiCC_container)) break; pMidiCC->setControlMin(pMidiCC_container, value); break; } label_control_min->setText(String(pInfo->pmin), juce::NotificationType::dontSendNotification); } void MidiCC_PopUp::SetMax() { synth_float_t value; param_info_t *pConstraints = pMidiCC->getConstraints(pMidiCC_container); param_info_t *pInfo = NULL; value = (synth_float_t)label_control_max->getText().getFloatValue(); while (doChangeParameter()) { pInfo = pMidiCC->getParam(pMidiCC_container); if (value > pConstraints->pmax) value = pConstraints->pmax; if (value < pInfo->pmin) value = pInfo->pmin; // Min == Max => crash if (value == pMidiCC->getParamMin(pMidiCC_container)) break; pMidiCC->setParamMax(pMidiCC_container, value); break; } while (!doChangeParameter()) { pInfo = pMidiCC->getControl(pMidiCC_container); value = (synth_float_t)label_control_max->getText().getFloatValue(); if (fabs(value) > fabs(pConstraints->pmax)) value = pConstraints->pmax*fabs(value)/value; // Min == Max => crash if (value == pMidiCC->getControlMin(pMidiCC_container)) break; pMidiCC->setControlMax(pMidiCC_container, value); break; } label_control_max->setText(String(pInfo->pmax), juce::NotificationType::dontSendNotification); } //[/MiscUserCode] //============================================================================== #if 0 /* -- Jucer information section -- This is where the Jucer puts all of its metadata, so don't change anything in here! BEGIN_JUCER_METADATA END_JUCER_METADATA */ #endif