diff --git a/include/app/AudioWidget.hpp b/include/app/AudioWidget.hpp index 5c77add8..abbc6758 100644 --- a/include/app/AudioWidget.hpp +++ b/include/app/AudioWidget.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -29,6 +30,14 @@ struct AudioDeviceWidget : LedDisplay { }; +/** A virtual audio port graphic that displays an audio menu when clicked. */ +struct AudioButton : SvgButton { + audio::Port* port; + void setAudioPort(audio::Port* port); + void onAction(const event::Action& e) override; +}; + + /** Appends menu items to the given menu with driver, device, etc. Useful alternative to putting an AudioWidget on your module's panel. */ diff --git a/include/app/MidiWidget.hpp b/include/app/MidiWidget.hpp index 9294b66d..da1c2096 100644 --- a/include/app/MidiWidget.hpp +++ b/include/app/MidiWidget.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include @@ -19,6 +20,14 @@ struct MidiWidget : LedDisplay { }; +/** A virtual MIDI port graphic that displays an MIDI menu when clicked. */ +struct MidiButton : SvgButton { + midi::Port* port; + void setMidiPort(midi::Port* port); + void onAction(const event::Action& e) override; +}; + + /** Appends menu items to the given menu with driver, device, etc. Useful alternative to putting a MidiWidget on your module's panel. */ diff --git a/include/componentlibrary.hpp b/include/componentlibrary.hpp index 7813fd0a..777a88e4 100644 --- a/include/componentlibrary.hpp +++ b/include/componentlibrary.hpp @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include @@ -804,5 +806,29 @@ struct SegmentDisplay : widget::Widget { }; +struct AudioButton_ADAT : app::AudioButton { + AudioButton_ADAT() { + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/ADAT.svg"))); + shadow->opacity = 0.0; + } +}; + + +struct AudioButton_USB_B : app::AudioButton { + AudioButton_USB_B() { + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/USB-B.svg"))); + shadow->opacity = 0.0; + } +}; + + +struct MidiButton_MIDI_DIN : app::MidiButton { + MidiButton_MIDI_DIN() { + addFrame(APP->window->loadSvg(asset::system("res/ComponentLibrary/MIDI_DIN.svg"))); + shadow->opacity = 0.0; + } +}; + + } // namespace componentlibrary } // namespace rack diff --git a/include/engine/Module.hpp b/include/engine/Module.hpp index 78ee96cd..6b1644dd 100644 --- a/include/engine/Module.hpp +++ b/include/engine/Module.hpp @@ -317,9 +317,9 @@ struct Module { /** DEPRECATED. Override `onSampleRateChange(e)` instead. */ virtual void onSampleRateChange() {} - /** private */ + /** Unstable API, do not use in plugins. */ float& cpuTime(); - /** private */ + /** Unstable API, do not use in plugins. */ bool& bypass(); }; diff --git a/src/app/AudioWidget.cpp b/src/app/AudioWidget.cpp index a805261c..bef47fab 100644 --- a/src/app/AudioWidget.cpp +++ b/src/app/AudioWidget.cpp @@ -337,6 +337,17 @@ void AudioDeviceWidget::setAudioPort(audio::Port* port) { } +void AudioButton::setAudioPort(audio::Port* port) { + this->port = port; +} + + +void AudioButton::onAction(const event::Action& e) { + ui::Menu* menu = createMenu(); + appendAudioMenu(menu, port); +} + + void appendAudioMenu(ui::Menu* menu, audio::Port* port) { menu->addChild(createMenuLabel("Audio driver")); appendAudioDriverMenu(menu, port); diff --git a/src/app/MidiWidget.cpp b/src/app/MidiWidget.cpp index 8f3216a7..5c383bba 100644 --- a/src/app/MidiWidget.cpp +++ b/src/app/MidiWidget.cpp @@ -197,6 +197,17 @@ void MidiWidget::setMidiPort(midi::Port* port) { } +void MidiButton::setMidiPort(midi::Port* port) { + this->port = port; +} + + +void MidiButton::onAction(const event::Action& e) { + ui::Menu* menu = createMenu(); + appendMidiMenu(menu, port); +} + + void appendMidiMenu(ui::Menu* menu, midi::Port* port) { menu->addChild(createMenuLabel("MIDI driver")); appendMidiDriverMenu(menu, port); diff --git a/src/core/AudioInterface.cpp b/src/core/AudioInterface.cpp index cf5f218e..c8c334f2 100644 --- a/src/core/AudioInterface.cpp +++ b/src/core/AudioInterface.cpp @@ -446,6 +446,15 @@ struct AudioInterfaceWidget : ModuleWidget { // Adjust deviceChoice position audioWidget->deviceChoice->textOffset = Vec(6, 14); addChild(audioWidget); + + AudioButton* m = createWidget(Vec()); + m->setAudioPort(module); + addChild(m); + + AudioButton* m2 = createWidget(Vec(0, 50)); + m2->setAudioPort(module); + addChild(m2); + } } diff --git a/src/core/MIDI_CV.cpp b/src/core/MIDI_CV.cpp index d52d9319..37b40775 100644 --- a/src/core/MIDI_CV.cpp +++ b/src/core/MIDI_CV.cpp @@ -506,6 +506,11 @@ struct MIDI_CVWidget : ModuleWidget { midiWidget->box.size = mm2px(Vec(33.840, 28)); midiWidget->setMidiPort(module ? &module->midiInput : NULL); addChild(midiWidget); + + + MidiButton* m = createWidget(Vec()); + m->setMidiPort(module ? &module->midiInput : NULL); + addChild(m); } void appendContextMenu(Menu* menu) override {