Browse Source

Add AudioButton and MidiButton and Component Library subclasses with graphics.

tags/v2.0.0
Andrew Belt 4 years ago
parent
commit
e80beefba4
8 changed files with 82 additions and 2 deletions
  1. +9
    -0
      include/app/AudioWidget.hpp
  2. +9
    -0
      include/app/MidiWidget.hpp
  3. +26
    -0
      include/componentlibrary.hpp
  4. +2
    -2
      include/engine/Module.hpp
  5. +11
    -0
      src/app/AudioWidget.cpp
  6. +11
    -0
      src/app/MidiWidget.cpp
  7. +9
    -0
      src/core/AudioInterface.cpp
  8. +5
    -0
      src/core/MIDI_CV.cpp

+ 9
- 0
include/app/AudioWidget.hpp View File

@@ -2,6 +2,7 @@
#include <app/common.hpp>
#include <app/LedDisplay.hpp>
#include <ui/Menu.hpp>
#include <app/SvgButton.hpp>
#include <audio.hpp>


@@ -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.
*/


+ 9
- 0
include/app/MidiWidget.hpp View File

@@ -2,6 +2,7 @@
#include <app/common.hpp>
#include <app/LedDisplay.hpp>
#include <ui/Menu.hpp>
#include <app/SvgButton.hpp>
#include <midi.hpp>


@@ -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.
*/


+ 26
- 0
include/componentlibrary.hpp View File

@@ -5,6 +5,8 @@
#include <app/ModuleLightWidget.hpp>
#include <app/SvgSwitch.hpp>
#include <app/SvgScrew.hpp>
#include <app/AudioWidget.hpp>
#include <app/MidiWidget.hpp>
#include <asset.hpp>


@@ -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

+ 2
- 2
include/engine/Module.hpp View File

@@ -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();
};



+ 11
- 0
src/app/AudioWidget.cpp View File

@@ -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);


+ 11
- 0
src/app/MidiWidget.cpp View File

@@ -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);


+ 9
- 0
src/core/AudioInterface.cpp View File

@@ -446,6 +446,15 @@ struct AudioInterfaceWidget : ModuleWidget {
// Adjust deviceChoice position
audioWidget->deviceChoice->textOffset = Vec(6, 14);
addChild(audioWidget);

AudioButton* m = createWidget<AudioButton_USB_B>(Vec());
m->setAudioPort(module);
addChild(m);

AudioButton* m2 = createWidget<AudioButton_ADAT>(Vec(0, 50));
m2->setAudioPort(module);
addChild(m2);

}
}



+ 5
- 0
src/core/MIDI_CV.cpp View File

@@ -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<MidiButton_MIDI_DIN>(Vec());
m->setMidiPort(module ? &module->midiInput : NULL);
addChild(m);
}

void appendContextMenu(Menu* menu) override {


Loading…
Cancel
Save