Skip to content

Commit

Permalink
UI: Add "Panic" button
Browse files Browse the repository at this point in the history
  • Loading branch information
AnClark committed Jul 29, 2023
1 parent fbe3a8a commit 8a55547
Show file tree
Hide file tree
Showing 6 changed files with 348 additions and 19 deletions.
310 changes: 292 additions & 18 deletions plugin/MinatonArtwork.cpp

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions plugin/MinatonArtwork.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ namespace MinatonArtwork
const unsigned int newknobWidth = 42;
const unsigned int newknobHeight = 42;

extern const char* panic_buttonData;
const unsigned int panic_buttonDataSize = 11200;
const unsigned int panic_buttonWidth = 70;
const unsigned int panic_buttonHeight = 40;

extern const char* panic_button_pressedData;
const unsigned int panic_button_pressedDataSize = 11200;
const unsigned int panic_button_pressedWidth = 70;
const unsigned int panic_button_pressedHeight = 40;

extern const char* sliderData;
const unsigned int sliderDataSize = 6084;
const unsigned int sliderWidth = 39;
Expand Down
33 changes: 32 additions & 1 deletion plugin/MinatonUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ MinatonUI::MinatonUI()
, fSwitchNoLightImage_OFF(Art::switch_off_nolightData, Art::switch_off_nolightWidth, Art::switch_off_nolightHeight, kImageFormatBGRA)
, fImgLabelMixMode(Art::mix_mode_labelData, Art::mix_mode_labelWidth, Art::mix_mode_labelHeight, kImageFormatBGRA)
, fImgLabelMonoStereo(Art::mono_stereo_labelData, Art::mono_stereo_labelWidth, Art::mono_stereo_labelHeight, kImageFormatBGRA)

, fImgPanicButton(Art::panic_buttonData, Art::panic_buttonWidth, Art::panic_buttonHeight)
, fImgPanicButton_Pressed(Art::panic_button_pressedData, Art::panic_button_pressedWidth, Art::panic_button_pressedHeight)
{
// Knob initial angles
constexpr int KNOB_ANGLE = 287;
Expand Down Expand Up @@ -100,6 +101,9 @@ MinatonUI::MinatonUI()
// Equalizer params
_createKnob(fCutOffFrequency, PARAM_FREQUENCY, 377, 368, KNOB_ANGLE);
_createKnob(fResonance, PARAM_RESONANCE, 377, 422, KNOB_ANGLE);

// Panic button
_createButton(fPanic, BTN_PANIC, fImgPanicButton, fImgPanicButton_Pressed, 452, 505);
}

void MinatonUI::parameterChanged(uint32_t index, float value)
Expand Down Expand Up @@ -279,6 +283,12 @@ void MinatonUI::parameterChanged(uint32_t index, float value)

void MinatonUI::imageButtonClicked(ImageButton* button, int)
{
switch (button->getId()) {
case BTN_PANIC: {
panic();
break;
}
}
}

void MinatonUI::imageSwitchClicked(ImageSwitch* button, bool down)
Expand Down Expand Up @@ -365,6 +375,27 @@ void MinatonUI::onDisplay()

void MinatonUI::idleCallback() { }

void MinatonUI::panic()
{
/**
There is no API to send MIDI data to DSP side. Instead, DPF provides UI::sendNote().
But we can still send any MIDI data via this method, simply doing a hack.
In method UI::sendNote(uint8_t channel, uint8_t note, uint8_t velocity):
`channel` will be converted into MIDI data 0 by:
`midi_data[0] = (velocity != 0 ? 0x90 : 0x80) | channel;`
To send MIDI controller data, we need to transform midi_data[0] into MIDI_STATUS_CONTROLLER (0xB0)
by simply applying a proper `channel` value. It would be easy to calculate:
0x80 | channel = 0xB0
=> 0b10000000 | channel = 0b10110000
=> channel = 0b00110000
=> channel = 0x30
*/
sendNote(0x30, 0x7B, 0); // MIDI_CC_ALL_NOTES_OFF = 0x7B
}

// -----------------------------------------------------------------------

UI* createUI()
Expand Down
14 changes: 14 additions & 0 deletions plugin/MinatonUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class MinatonUI : public UI,
Image fSwitchButtonImage_ON, fSwitchButtonImage_OFF;
Image fSwitchNoLightImage_ON, fSwitchNoLightImage_OFF;
Image fImgLabelMixMode, fImgLabelMonoStereo;
Image fImgPanicButton, fImgPanicButton_Pressed;
// ImageAboutWindow fAboutWindow;

// -------------------------------------------------------------------
Expand Down Expand Up @@ -93,6 +94,8 @@ class MinatonUI : public UI,

ScopedPointer<ImageKnob> fMasterVolume;

ScopedPointer<ImageButton> fPanic;

// -------------------------------------------------------------------
// Helpers

Expand All @@ -101,10 +104,21 @@ class MinatonUI : public UI,
void _createSwitchButton(ScopedPointer<ImageSwitch>& switchButton, MinatonParamId paramId, uint absolutePosX, uint absolutePosY, bool withLight = true);
void _createButton(ScopedPointer<ImageButton>& button, uint id, Image& imageNormal, Image& imagePressed, uint absolutePosX, uint absolutePosY);

// -------------------------------------------------------------------
// Control plugin from UI side

void panic();

DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(MinatonUI)
};

// -----------------------------------------------------------------------

// --------------------------------
// Button IDs

constexpr uint BTN_PANIC = d_cconst('p', 'n', 'i', 'c');

// -----------------------------------------------------------------------

END_NAMESPACE_DISTRHO
Binary file added plugin/artwork/panic_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added plugin/artwork/panic_button_pressed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8a55547

Please sign in to comment.