2
0
Fork 0
OB-Xd/Source/PluginEditor.cpp

1520 lines
57 KiB
C++
Raw Normal View History

2017-01-23 10:15:08 +00:00
/*
==============================================================================
This file was auto-generated by the Introjucer!
It contains the basic startup code for a Juce application.
==============================================================================
*/
#include "PluginProcessor.h"
#include "PluginEditor.h"
#include <utility>
2021-09-01 08:38:39 +00:00
#include "Gui/ImageButton.h"
2017-01-23 10:15:08 +00:00
// #include "GUI/BinaryData.h"
#include "Utils.h"
2017-01-23 10:15:08 +00:00
2017-01-23 10:15:08 +00:00
//==============================================================================
ObxdAudioProcessorEditor::ObxdAudioProcessorEditor (ObxdAudioProcessor& ownerFilter)
2021-09-01 08:38:39 +00:00
: AudioProcessorEditor (&ownerFilter), ScalableComponent(&ownerFilter), processor (ownerFilter),
2020-05-10 09:15:47 +00:00
skinFolder (processor.getSkinFolder()),
progStart (3000),
bankStart (2000),
skinStart (1000),
2020-05-10 09:15:47 +00:00
skins (processor.getSkinFiles()),
banks (processor.getBankFiles())
2017-01-23 10:15:08 +00:00
{
2021-09-17 12:16:21 +00:00
setLookAndFeel(new CustomLookAndFeel(&this->processor));
//LookAndFeel& lf = getLookAndFeel();
// Popup Menu Look and Feel
2021-09-17 12:16:21 +00:00
//lf.setColour(PopupMenu::backgroundColourId, Colour(20, 20, 20));
//lf.setColour(PopupMenu::textColourId, Colour(245, 245, 245));
//lf.setColour(PopupMenu::highlightedBackgroundColourId, Colour(60, 60, 60));
//skinFolder = ownerFilter.getCurrentSkinFolder(); // initialized above
commandManager.registerAllCommandsForTarget(this);
commandManager.setFirstCommandTarget(this);
// reset KeyPressMappingSet
commandManager.getKeyMappings()->resetToDefaultMappings();
// having set up the default key-mappings, you might now want to load the last set
// of mappings that the user configured.
//commandManager.getKeyMappings()->restoreFromXml(lastSavedKeyMappingsXML);
// Now tell our top-level window to send any keypresses that arrive to the
// KeyPressMappingSet, which will use them to invoke the appropriate commands.
//addKeyListener(commandManager.getKeyMappings());
getTopLevelComponent()->addKeyListener (commandManager.getKeyMappings());
//Timer::callAfterDelay (100, [this] { this->grabKeyboardFocus(); }); // ensure that key presses are sent to the KeyPressTarget object
if (PluginHostType().isProTools()) { } else { startTimer(100); }; // Fix ProTools file dialog focus issues
2021-05-12 16:47:15 +00:00
//startTimer(100); // This will fix the issue
2021-04-27 07:46:19 +00:00
DBG("W: " <<getWidth() << " H:" << getHeight());
2020-05-10 09:15:47 +00:00
loadSkin (processor);
2021-09-01 08:38:39 +00:00
updateFromHost();
2021-09-01 08:38:39 +00:00
switch(processor.gui_size)
{
case 1:
ScalableComponent::setScaleFactor(1.0f, isHighResolutionDisplay());
break;
case 2:
ScalableComponent::setScaleFactor(1.5f, isHighResolutionDisplay());
break;
case 4:
ScalableComponent::setScaleFactor(2.0f, isHighResolutionDisplay());
break;
}
repaint();
scaleFactorChanged();
2020-04-21 13:08:05 +00:00
}
void ObxdAudioProcessorEditor::resized() {
if (setPresetNameWindow != nullptr )
{
if (auto wrapper = dynamic_cast<ObxdAudioProcessorEditor*>(processor.getActiveEditor()))
{
auto w = proportionOfWidth(0.25f);
auto h = proportionOfHeight(0.3f);
auto x = proportionOfWidth(0.5f) - (w / 2);
auto y = wrapper->getY();
if (setPresetNameWindow != nullptr)
{
y += proportionOfHeight(0.15f);
setPresetNameWindow->setBounds(x, y, w, h);
}
}
}
2021-09-01 08:38:39 +00:00
skinFolder = processor.getCurrentSkinFolder();
File coords = skinFolder.getChildFile ("coords.xml");
if (!coords.existsAsFile()) {
return;
}
XmlDocument skin (coords);
auto doc = skin.getDocumentElement();
if (doc){
//int xScreen = getWidth(), yScreen = getHeight();
if (doc->getTagName() == "PROPERTIES"){
forEachXmlChildElementWithTagName(*doc, child, "VALUE"){
if (child->hasAttribute("NAME") && child->hasAttribute("x") && child->hasAttribute("y")) {
String name = child->getStringAttribute("NAME");
int x = child->getIntAttribute("x");
int y = child->getIntAttribute("y");
int d = child->getIntAttribute("d");
int w = child->getIntAttribute("w");
int h = child->getIntAttribute("h");
bool tooltipEnabled = child->getBoolAttribute("tooltip", false);
2021-09-01 08:38:39 +00:00
DBG(" COmponent : " << name);
if (mappingComps[name] != nullptr){
if (auto* knob = dynamic_cast<Knob*>(mappingComps[name])){
knob->setBounds(transformBounds(x, y, d,d));
if (!tooltipEnabled)
knob->setPopupDisplayEnabled(false, false, nullptr);
2021-09-01 08:38:39 +00:00
}
else if (dynamic_cast<ButtonList*>(mappingComps[name])){
mappingComps[name]->setBounds(transformBounds(x, y, w, h));
2021-09-09 15:30:38 +00:00
//((ButtonList *)mappingComps[name])->getRootMenu()->setLookAndFeel(& getLookAndFeel());
2021-09-01 08:38:39 +00:00
}
else if (dynamic_cast<TooglableButton*>(mappingComps[name])){
mappingComps[name]->setBounds(transformBounds(x, y, w, h));
}
else if (dynamic_cast<ImageMenu*>(mappingComps[name])){
mappingComps[name]->setBounds(transformBounds(x, y, d, d));
}
else if (dynamic_cast<ImageButton*>(mappingComps[name])){
mappingComps[name]->setBounds(transformBounds(x, y, w, h));
}
}
}
}
}
}
}
2020-05-10 09:15:47 +00:00
void ObxdAudioProcessorEditor::loadSkin (ObxdAudioProcessor& ownerFilter)
{
knobAttachments.clear();
buttonListAttachments.clear();
toggleAttachments.clear();
2020-04-24 06:15:00 +00:00
imageButtons.clear();
2020-05-10 09:15:47 +00:00
popupMenus.clear();
2021-09-01 08:38:39 +00:00
mappingComps.clear();
2020-04-21 13:08:05 +00:00
ownerFilter.removeChangeListener (this);
2021-09-01 08:38:39 +00:00
2020-04-21 13:08:05 +00:00
skinFolder = ownerFilter.getCurrentSkinFolder();
2020-04-20 20:57:41 +00:00
File coords = skinFolder.getChildFile ("coords.xml");
bool useClassicSkin = coords.existsAsFile();
if (!useClassicSkin) {
2021-09-01 08:38:39 +00:00
addMenuButton (14, 25, 20, "menu");
2020-05-09 18:26:24 +00:00
rebuildComponents (processor);
return;
2020-04-20 20:57:41 +00:00
}
2020-12-06 13:57:23 +00:00
//if (coords.createInputStream())
2020-04-20 20:57:41 +00:00
XmlDocument skin (coords);
auto doc = skin.getDocumentElement();
2020-12-06 13:57:23 +00:00
if (!doc) {
notLoadSkin = true;
setSize (1440, 450);
}
else {
2021-05-17 17:52:09 +00:00
int xScreen = getWidth(), yScreen = getHeight();
if (doc->getTagName() == "PROPERTIES"){
2021-05-17 17:52:09 +00:00
forEachXmlChildElementWithTagName(*doc, child, "VALUE"){
if (child->hasAttribute("NAME") && child->hasAttribute("x") && child->hasAttribute("y")) {
2020-04-20 20:57:41 +00:00
String name = child->getStringAttribute("NAME");
int x = child->getIntAttribute("x");
int y = child->getIntAttribute("y");
int d = child->getIntAttribute("d");
2020-04-21 09:54:19 +00:00
int w = child->getIntAttribute("w");
int h = child->getIntAttribute("h");
2020-04-21 13:08:05 +00:00
2021-09-01 08:38:39 +00:00
if (name == "resonanceKnob"){
resonanceKnob = addKnob (x, y, d, ownerFilter, RESONANCE, "Resonance", 0);
mappingComps["resonanceKnob"] = resonanceKnob;
}
if (name == "cutoffKnob"){
cutoffKnob = addKnob (x, y, d, ownerFilter, CUTOFF, "Cutoff", 0.4);
mappingComps["cutoffKnob"] = cutoffKnob;
}
if (name == "filterEnvelopeAmtKnob"){
filterEnvelopeAmtKnob = addKnob (x, y, d, ownerFilter, ENVELOPE_AMT, "Envelope", 0);
mappingComps["filterEnvelopeAmtKnob"] = filterEnvelopeAmtKnob;
}
if (name == "multimodeKnob"){
multimodeKnob = addKnob (x, y, d, ownerFilter, MULTIMODE, "Multimode", 0.5);
mappingComps["multimodeKnob"] = multimodeKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "volumeKnob"){
volumeKnob = addKnob (x, y, d, ownerFilter, VOLUME, "Volume", 0.4);
mappingComps["volumeKnob"] = volumeKnob;
}
if (name == "portamentoKnob"){
portamentoKnob = addKnob (x, y, d, ownerFilter, PORTAMENTO, "Portamento", 0);
mappingComps["portamentoKnob"] = portamentoKnob;
}
if (name == "osc1PitchKnob"){
osc1PitchKnob = addKnob (x, y, d, ownerFilter, OSC1P, "Osc1Pitch", 0);
osc1PitchKnob->shiftDragCallback = [](double value)
{
if (value < 0.125) return 0.0;
if (value < 0.375) return 0.25;
if (value < 0.625) return 0.5;
if (value < 0.875) return 0.75;
return 1.0;
};
2021-09-01 08:38:39 +00:00
mappingComps["osc1PitchKnob"] = osc1PitchKnob;
}
if (name == "pulseWidthKnob"){
pulseWidthKnob = addKnob (x, y, d, ownerFilter, PW, "PW", 0);
mappingComps["pulseWidthKnob"] = pulseWidthKnob;
}
if (name == "osc2PitchKnob"){
osc2PitchKnob = addKnob (x, y, d, ownerFilter, OSC2P, "Osc2Pitch", 0);
osc2PitchKnob->shiftDragCallback = [](double value)
{
if (value < 0.125) return 0.0;
if (value < 0.375) return 0.25;
if (value < 0.625) return 0.5;
if (value < 0.875) return 0.75;
return 1.0;
};
2021-09-01 08:38:39 +00:00
mappingComps["osc2PitchKnob"] = osc2PitchKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "osc1MixKnob"){
osc1MixKnob = addKnob (x, y, d, ownerFilter, OSC1MIX, "Osc1", 1);
mappingComps["osc1MixKnob"] = osc1MixKnob;
}
if (name == "osc2MixKnob"){
osc2MixKnob = addKnob (x, y, d, ownerFilter, OSC2MIX, "Osc2", 1);
mappingComps["osc2MixKnob"] = osc2MixKnob;
}
if (name == "noiseMixKnob"){
noiseMixKnob = addKnob (x, y, d, ownerFilter, NOISEMIX, "Noise", 0);
mappingComps["noiseMixKnob"] = noiseMixKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "xmodKnob"){
xmodKnob = addKnob (x, y, d, ownerFilter, XMOD, "Xmod", 0);
mappingComps["xmodKnob"] = xmodKnob;
}
if (name == "osc2DetuneKnob"){
osc2DetuneKnob = addKnob (x, y, d, ownerFilter, OSC2_DET, "Detune", 0);
mappingComps["osc2DetuneKnob"] = osc2DetuneKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "envPitchModKnob"){
envPitchModKnob = addKnob (x, y, d, ownerFilter, ENVPITCH, "PEnv", 0);
mappingComps["envPitchModKnob"] = envPitchModKnob;
}
if (name == "brightnessKnob"){
brightnessKnob = addKnob (x, y, d, ownerFilter, BRIGHTNESS, "Bri", 1);
mappingComps["brightnessKnob"] = brightnessKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "attackKnob"){
attackKnob = addKnob (x, y, d, ownerFilter, LATK, "Atk", 0);
mappingComps["attackKnob"] = attackKnob;
}
if (name == "decayKnob"){ decayKnob = addKnob (x, y, d, ownerFilter, LDEC, "Dec", 0);
mappingComps["decayKnob"] = decayKnob;
}
if (name == "sustainKnob"){
sustainKnob = addKnob (x, y, d, ownerFilter, LSUS, "Sus", 1);
mappingComps["sustainKnob"] = sustainKnob;
}
if (name == "releaseKnob"){
releaseKnob = addKnob (x, y, d, ownerFilter, LREL, "Rel", 0);
mappingComps["releaseKnob"] = releaseKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "fattackKnob"){
fattackKnob = addKnob (x, y, d, ownerFilter, FATK, "Atk", 0);
mappingComps["fattackKnob"] = fattackKnob;
}
if (name == "fdecayKnob"){
fdecayKnob = addKnob (x, y, d, ownerFilter, FDEC, "Dec", 0);
mappingComps["fdecayKnob"] = fdecayKnob;
}
if (name == "fsustainKnob"){
fsustainKnob = addKnob (x, y, d, ownerFilter, FSUS, "Sus", 1);
mappingComps["fsustainKnob"] = fsustainKnob;
}
if (name == "freleaseKnob"){
freleaseKnob = addKnob (x, y, d, ownerFilter, FREL, "Rel", 0);
mappingComps["freleaseKnob"] = freleaseKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "lfoFrequencyKnob"){
lfoFrequencyKnob = addKnob (x, y, d, ownerFilter, LFOFREQ, "Freq", 0);
mappingComps["lfoFrequencyKnob"] = lfoFrequencyKnob;
}
if (name == "lfoAmt1Knob"){
lfoAmt1Knob = addKnob (x, y, d, ownerFilter, LFO1AMT, "Pitch", 0);
mappingComps["lfoAmt1Knob"] = lfoAmt1Knob;
}
if (name == "lfoAmt2Knob"){
lfoAmt2Knob = addKnob (x, y, d, ownerFilter, LFO2AMT, "PWM", 0);
mappingComps["lfoAmt2Knob"] = lfoAmt2Knob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "lfoSinButton"){
lfoSinButton = addButton (x, y, w, h, ownerFilter, LFOSINWAVE, "Sin");
mappingComps["lfoSinButton"] = lfoSinButton;
}
if (name == "lfoSquareButton"){
lfoSquareButton = addButton (x, y, w, h, ownerFilter, LFOSQUAREWAVE, "SQ");
mappingComps["lfoSquareButton"] = lfoSquareButton;
}
if (name == "lfoSHButton"){
lfoSHButton = addButton (x, y, w, h, ownerFilter, LFOSHWAVE, "S&H");
mappingComps["lfoSHButton"] = lfoSHButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "lfoOsc1Button"){
lfoOsc1Button = addButton (x, y, w, h, ownerFilter, LFOOSC1, "Osc1");
mappingComps["lfoOsc1Button"] = lfoOsc1Button;
}
if (name == "lfoOsc2Button"){
lfoOsc2Button = addButton (x, y, w, h, ownerFilter, LFOOSC2, "Osc2");
mappingComps["lfoOsc2Button"] = lfoOsc2Button;
}
if (name == "lfoFilterButton"){
lfoFilterButton = addButton (x, y, w, h, ownerFilter, LFOFILTER, "Filt");
mappingComps["lfoFilterButton"] = lfoFilterButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "lfoPwm1Button"){
lfoPwm1Button = addButton (x, y, w, h, ownerFilter, LFOPW1, "Osc1");
mappingComps["lfoPwm1Button"] = lfoPwm1Button;
}
if (name == "lfoPwm2Button"){
lfoPwm2Button = addButton (x, y, w, h, ownerFilter, LFOPW2, "Osc2");
mappingComps["lfoPwm2Button"] = lfoPwm2Button;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "hardSyncButton"){
hardSyncButton = addButton (x, y, w, h, ownerFilter, OSC2HS, "Sync");
mappingComps["hardSyncButton"] = hardSyncButton;
}
if (name == "osc1SawButton"){
osc1SawButton = addButton (x, y, w, h, ownerFilter, OSC1Saw, "S");
mappingComps["osc1SawButton"] = osc1SawButton;
}
if (name == "osc2SawButton"){
osc2SawButton = addButton (x, y, w, h, ownerFilter, OSC2Saw, "S");
mappingComps["osc2SawButton"] = osc2SawButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "osc1PulButton"){
osc1PulButton = addButton (x, y, w, h, ownerFilter, OSC1Pul, "P");
mappingComps["osc1PulButton"] = osc1PulButton;
}
if (name == "osc2PulButton"){
osc2PulButton = addButton (x, y, w, h, ownerFilter, OSC2Pul, "P");
mappingComps["osc2PulButton"] = osc2PulButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "pitchQuantButton"){
pitchQuantButton = addButton (x, y, w, h, ownerFilter, OSCQuantize, "Step");
mappingComps["pitchQuantButton"] = pitchQuantButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "filterBPBlendButton"){
filterBPBlendButton = addButton (x, y, w, h, ownerFilter, BANDPASS, "Bp");
mappingComps["filterBPBlendButton"] = filterBPBlendButton;
}
if (name == "fourPoleButton"){
fourPoleButton = addButton (x, y, w, h, ownerFilter, FOURPOLE, "24");
mappingComps["fourPoleButton"] = fourPoleButton;
}
if (name == "filterHQButton"){
filterHQButton = addButton (x, y, w, h, ownerFilter, FILTER_WARM, "HQ");
mappingComps["filterHQButton"] = filterHQButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "filterKeyFollowButton"){
filterKeyFollowButton = addButton (x, y, w, h, ownerFilter, FLT_KF, "Key");
mappingComps["filterKeyFollowButton"] = filterKeyFollowButton;
}
if (name == "unisonButton"){
unisonButton = addButton (x, y, w, h, ownerFilter, UNISON, "Uni");
mappingComps["unisonButton"] = unisonButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "tuneKnob"){
tuneKnob = addKnob (x, y, d, ownerFilter, TUNE, "Tune", 0.5);
mappingComps["tuneKnob"] = tuneKnob;
}
if (name == "transposeKnob"){
transposeKnob = addKnob (x, y, d, ownerFilter, OCTAVE, "Transpose", 0.5);
mappingComps["transposeKnob"] = transposeKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "voiceDetuneKnob"){
voiceDetuneKnob =addKnob (x, y, d, ownerFilter, UDET, "VoiceDet", 0);
mappingComps["voiceDetuneKnob"] = voiceDetuneKnob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "bendLfoRateKnob"){
bendLfoRateKnob = addKnob (x, y, d, ownerFilter, BENDLFORATE, "ModRate", 0.4);
mappingComps["bendLfoRateKnob"] = bendLfoRateKnob;
}
if (name == "veloFltEnvKnob"){
veloFltEnvKnob = addKnob (x, y, d, ownerFilter, VFLTENV, "VFE", 0);
mappingComps["veloFltEnvKnob"] = veloFltEnvKnob;
}
if (name == "veloAmpEnvKnob"){
veloAmpEnvKnob = addKnob (x, y, d, ownerFilter, VAMPENV, "VAE", 0);
mappingComps["veloAmpEnvKnob"] = veloAmpEnvKnob;
}
if (name == "midiLearnButton"){
midiLearnButton = addButton (x, y, w, h, ownerFilter, MIDILEARN, "LEA");
mappingComps["midiLearnButton"] = midiLearnButton;
}
if (name == "midiUnlearnButton"){
midiUnlearnButton = addButton (x, y, w, h, ownerFilter, UNLEARN, "UNL");
mappingComps["midiUnlearnButton"] = midiUnlearnButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "pan1Knob"){
pan1Knob = addKnob (x, y, d, ownerFilter, PAN1, "1", 0.5);
pan1Knob->resetOnShiftClick(true, Action::panReset);
pan1Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan1Knob"] = pan1Knob;
}
if (name == "pan2Knob"){
pan2Knob = addKnob (x, y, d, ownerFilter, PAN2, "2", 0.5);
pan2Knob->resetOnShiftClick(true, Action::panReset);
pan2Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan2Knob"] = pan2Knob;
}
if (name == "pan3Knob"){
pan3Knob = addKnob (x, y, d, ownerFilter, PAN3, "3", 0.5);
pan3Knob->resetOnShiftClick(true, Action::panReset);
pan3Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan3Knob"] = pan3Knob;
}
if (name == "pan4Knob"){
pan4Knob = addKnob (x, y, d, ownerFilter, PAN4, "4", 0.5);
pan4Knob->resetOnShiftClick(true, Action::panReset);
pan4Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan4Knob"] = pan4Knob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "pan5Knob"){
pan5Knob = addKnob (x, y, d, ownerFilter, PAN5, "5", 0.5);
pan5Knob->resetOnShiftClick(true, Action::panReset);
pan5Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan5Knob"] = pan5Knob;
}
if (name == "pan6Knob"){
pan6Knob = addKnob (x, y, d, ownerFilter, PAN6, "6", 0.5);
pan6Knob->resetOnShiftClick(true, Action::panReset);
pan6Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan6Knob"] = pan6Knob;
}
if (name == "pan7Knob"){
pan7Knob = addKnob (x, y, d, ownerFilter, PAN7, "7", 0.5);
pan7Knob->resetOnShiftClick(true, Action::panReset);
pan7Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan7Knob"] = pan7Knob;
}
if (name == "pan8Knob"){
pan8Knob = addKnob (x, y, d, ownerFilter, PAN8, "8", 0.5);
pan8Knob->resetOnShiftClick(true, Action::panReset);
pan8Knob->addActionListener(this);
2021-09-01 08:38:39 +00:00
mappingComps["pan8Knob"] = pan8Knob;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "bendOsc2OnlyButton"){
bendOsc2OnlyButton = addButton (x, y, w, h, ownerFilter, BENDOSC2, "Osc2");
mappingComps["bendOsc2OnlyButton"] = bendOsc2OnlyButton;
}
if (name == "bendRangeButton"){
bendRangeButton = addButton (x, y, w, h, ownerFilter, BENDRANGE, "12");
mappingComps["bendRangeButton"] = bendRangeButton;
}
if (name == "asPlayedAllocButton"){
asPlayedAllocButton = addButton (x, y, w, h, ownerFilter, ASPLAYEDALLOCATION, "APA");
mappingComps["asPlayedAllocButton"] = asPlayedAllocButton;
}
2020-04-20 20:57:41 +00:00
2021-09-01 08:38:39 +00:00
if (name == "filterDetuneKnob"){
filterDetuneKnob = addKnob (x, y, d, ownerFilter, FILTERDER, "Flt", 0.2);
mappingComps["filterDetuneKnob"] = filterDetuneKnob;
}
if (name == "portamentoDetuneKnob"){
portamentoDetuneKnob = addKnob (x, y, d, ownerFilter, PORTADER, "Port", 0.2);
mappingComps["portamentoDetuneKnob"] = portamentoDetuneKnob;
}
if (name == "envelopeDetuneKnob"){
envelopeDetuneKnob = addKnob (x, y, d, ownerFilter, ENVDER, "Env", 0.2);
mappingComps["envelopeDetuneKnob"] = envelopeDetuneKnob;
}
2020-04-21 13:08:05 +00:00
if (name == "voiceSwitch"){
2021-09-01 08:38:39 +00:00
voiceSwitch = addList (x, y, w, h, ownerFilter, VOICE_COUNT, "VoiceCount", "voices");
2021-09-17 12:16:21 +00:00
voiceSwitch->setLookAndFeel(&this->getLookAndFeel());
2021-09-01 08:38:39 +00:00
mappingComps["voiceSwitch"] = voiceSwitch;
}
2020-04-21 13:08:05 +00:00
if (name == "legatoSwitch"){
2021-09-01 08:38:39 +00:00
legatoSwitch = addList (x, y, w, h, ownerFilter, LEGATOMODE, "Legato", "legato");
2021-09-17 12:16:21 +00:00
legatoSwitch->setLookAndFeel(&this->getLookAndFeel());
2021-09-01 08:38:39 +00:00
mappingComps["legatoSwitch"] = legatoSwitch;
}
2020-04-20 20:57:41 +00:00
2020-04-24 06:15:00 +00:00
if (name == "menu")
{
2021-09-01 08:38:39 +00:00
ImageButton *img = addMenuButton (x, y, d, "menu");
mappingComps["menu"] = img;
2020-04-24 06:15:00 +00:00
}
/*
if (name == "guisize") {
xScreen = x;
yScreen = y;
if (processor.getShowPresetBar()) {
setSize(xScreen, yScreen + 40);
}
else {
setSize(xScreen, yScreen);
}
}
*/
2020-04-24 07:04:52 +00:00
2020-04-20 20:57:41 +00:00
//DBG(" Name: " << name << " X: " <<x <<" Y: "<<y);
}
}
}
2021-05-17 17:52:09 +00:00
presetBar.reset(new PresetBar(*this));
addAndMakeVisible(*presetBar);
presetBar->setVisible(processor.getShowPresetBar());
presetBar->leftClicked = [this](juce::Point<int> &pos){
PopupMenu menu;
2021-09-17 12:16:21 +00:00
menu.setLookAndFeel(&this->getLookAndFeel());
for (int i = 0; i < processor.getNumPrograms(); ++i)
{
menu.addItem (i + progStart + 1,
processor.getProgramName (i),
true,
i == processor.getCurrentProgram());
}
int result = menu.showAt (Rectangle<int> (pos.getX(), pos.getY(), 1, 1));
if (result >= (progStart + 1) && result <= (progStart + processor.getNumPrograms())){
result -= 1;
result -= progStart;
processor.setCurrentProgram (result);
}
};
resized();
2020-04-20 20:57:41 +00:00
}
// Prepare data
2020-05-10 09:15:47 +00:00
if (voiceSwitch)
{
2020-04-20 20:57:41 +00:00
for (int i = 1; i <= 32; ++i)
{
voiceSwitch->addChoice (String (i));
}
2020-05-10 09:15:47 +00:00
auto voiceOption = ownerFilter.getPluginState().getParameter (ownerFilter.getEngineParameterId (VOICE_COUNT))->getValue();
voiceSwitch->setValue (voiceOption, dontSendNotification);
2020-04-20 20:57:41 +00:00
}
2020-05-10 09:15:47 +00:00
if (legatoSwitch)
{
2020-04-20 20:57:41 +00:00
legatoSwitch->addChoice ("Keep All");
legatoSwitch->addChoice ("Keep Filter Envelope");
legatoSwitch->addChoice ("Keep Amplitude Envelope");
legatoSwitch->addChoice ("Retrig");
2020-05-10 09:15:47 +00:00
auto legatoOption = ownerFilter.getPluginState().getParameter (ownerFilter.getEngineParameterId (LEGATOMODE))->getValue();
legatoSwitch->setValue (legatoOption, dontSendNotification);
2020-04-20 20:57:41 +00:00
}
2020-04-24 06:15:00 +00:00
2020-05-10 09:15:47 +00:00
createMenu();
2021-04-27 07:46:19 +00:00
2020-04-21 13:08:05 +00:00
ownerFilter.addChangeListener (this);
2021-09-01 08:38:39 +00:00
scaleFactorChanged();
2020-04-20 20:57:41 +00:00
repaint();
2017-01-23 10:15:08 +00:00
}
ObxdAudioProcessorEditor::~ObxdAudioProcessorEditor()
{
processor.removeChangeListener (this);
// deleteAllChildren(); // WATCH OUT!
2017-01-23 10:15:08 +00:00
}
2021-09-01 08:38:39 +00:00
void ObxdAudioProcessorEditor::scaleFactorChanged()
{
// update background
const bool highResolutionDisplay = isHighResolutionDisplay();
const float scaleFactor = getScaleFactor();
// notify child components
for (int i = 0; i < getNumChildComponents(); i++)
{
ScalableComponent* object =
dynamic_cast<ScalableComponent*>(getChildComponent(i));
if (object != nullptr)
{
object->setScaleFactor(scaleFactor, highResolutionDisplay);
}
2021-09-09 15:30:38 +00:00
// update look and feel
CustomLookAndFeel* laf =
dynamic_cast<CustomLookAndFeel*>(&getChildComponent(i)->getLookAndFeel());
if (laf != nullptr)
{
laf->setScaleFactor(scaleFactor, highResolutionDisplay);
}
2021-09-01 08:38:39 +00:00
}
2021-09-09 15:30:38 +00:00
2021-09-01 08:38:39 +00:00
// redraw everything
backgroundImage = getScaledImageFromCache("main", scaleFactor, highResolutionDisplay);
int width = backgroundImage.getWidth();
int height = backgroundImage.getHeight();
if (!highResolutionDisplay)
{
if (scaleFactor == 1.5f)
{
width = roundFloatToInt(width * 0.75f);
height = roundFloatToInt(height * 0.75f);
}
else if (scaleFactor == 2.0f)
{
width /= 2;
height /= 2;
}
} else {
if (scaleFactor == 1.0f) //2x image
{
width /= 2;
height /= 2;
}
else if (scaleFactor == 1.5f) //4x images =>150%
{
width = roundFloatToInt(width * (0.25f + 0.125f));
height = roundFloatToInt(height * (0.25f + 0.125f));
}
else if (scaleFactor == 2.0f) //4x images =>200x
{
width /= 2;
height /= 2;
}
}
if (processor.getShowPresetBar())
{
setSize(width, height + presetBar->getHeight());
presetBar->setBounds((width - presetBar->getWidth()) / 2, height, presetBar->getWidth(), presetBar->getHeight());
} else
setSize(width, height);
}
void ObxdAudioProcessorEditor::placeLabel (int x, int y, String text)
2017-01-23 10:15:08 +00:00
{
Label* lab = new Label();
lab->setBounds (x, y, 110, 20);
lab->setJustificationType (Justification::centred);
lab->setText (text,dontSendNotification);
lab->setInterceptsMouseClicks (false, true);
addAndMakeVisible (lab);
2017-01-23 10:15:08 +00:00
}
2021-09-01 08:38:39 +00:00
ButtonList* ObxdAudioProcessorEditor::addList (int x, int y, int width, int height, ObxdAudioProcessor& filter, int parameter, String /*name*/, String imgName)
2017-01-23 10:15:08 +00:00
{
2020-08-10 10:59:00 +00:00
#if JUCE_WINDOWS || JUCE_LINUX
2021-09-01 08:38:39 +00:00
ButtonList *bl = new ButtonList (imgName, height, &processor);
2020-08-10 10:59:00 +00:00
#else
2021-09-01 08:38:39 +00:00
ButtonList *bl = new ButtonList (imgName, height, &processor);
2020-08-10 10:59:00 +00:00
#endif
2020-05-10 09:15:47 +00:00
buttonListAttachments.add (new ButtonList::ButtonListAttachment (filter.getPluginState(),
filter.getEngineParameterId (parameter),
*bl));
2020-04-21 09:54:19 +00:00
bl->setBounds (x, y, width, height);
addAndMakeVisible (bl);
2017-01-23 10:15:08 +00:00
return bl;
}
2020-04-21 08:53:36 +00:00
Knob* ObxdAudioProcessorEditor::addKnob (int x, int y, int d, ObxdAudioProcessor& filter, int parameter, String /*name*/, float defval)
2017-01-23 10:15:08 +00:00
{
2021-09-01 08:38:39 +00:00
Knob* knob = new Knob ("knob", 48, &processor);
2020-05-10 09:15:47 +00:00
knobAttachments.add (new Knob::KnobAttachment (filter.getPluginState(),
filter.getEngineParameterId (parameter),
*knob));
knob->setSliderStyle (Slider::RotaryVerticalDrag);
knob->setTextBoxStyle (knob->NoTextBox, true, 0, 0);
knob->setRange (0, 1);
2020-04-21 13:08:05 +00:00
knob->setBounds (x, y, d+(d/6), d+(d/6));
knob->setTextBoxIsEditable (false);
knob->setDoubleClickReturnValue (true, defval);
2020-05-10 09:15:47 +00:00
knob->setValue (filter.getPluginState().getParameter (filter.getEngineParameterId (parameter))->getValue());
addAndMakeVisible (knob);
2017-01-23 10:15:08 +00:00
return knob;
}
2020-04-21 13:08:05 +00:00
2020-05-10 09:15:47 +00:00
void ObxdAudioProcessorEditor::clean()
{
2020-04-21 13:08:05 +00:00
this->removeAllChildren();
}
2020-04-21 14:51:05 +00:00
TooglableButton* ObxdAudioProcessorEditor::addButton (int x, int y, int w, int h, ObxdAudioProcessor& filter, int parameter, String name)
2017-01-23 10:15:08 +00:00
{
2021-09-01 08:38:39 +00:00
TooglableButton* button = new TooglableButton ("button", &processor);
2020-08-06 16:09:15 +00:00
if (parameter != UNLEARN){
toggleAttachments.add (new AudioProcessorValueTreeState::ButtonAttachment (filter.getPluginState(),
2020-08-06 16:09:15 +00:00
filter.getEngineParameterId (parameter),
*button));
} else {
button->addListener(this);
}
2020-05-10 09:15:47 +00:00
button->setBounds (x, y, w, h);
button->setButtonText (name);
button->setToggleState(filter.getPluginState().getParameter (filter.getEngineParameterId (parameter))->getValue(),
2020-05-10 09:15:47 +00:00
dontSendNotification);
2020-08-06 16:09:15 +00:00
2020-05-10 09:15:47 +00:00
addAndMakeVisible (button);
2017-01-23 10:15:08 +00:00
return button;
}
void ObxdAudioProcessorEditor::actionListenerCallback(const String& message)
{
if (message.equalsIgnoreCase(Action::panReset))
{
const StringArray parameters{ "pan1Knob", "pan2Knob", "pan3Knob", "pan4Knob", "pan5Knob", "pan6Knob", "pan7Knob", "pan8Knob" };
for (const auto& parameter : parameters)
{
if (auto* knob = dynamic_cast<Knob*>(mappingComps[parameter]))
{
knob->setValue(knob->getDoubleClickReturnValue());
}
}
}
}
2021-09-01 08:38:39 +00:00
Rectangle<int> ObxdAudioProcessorEditor::transformBounds(int x, int y, int w, int h)
{
if (getScaleFactor() == 1.0f)
return Rectangle<int>(x, y, w, h);
2017-01-23 10:15:08 +00:00
2021-09-01 08:38:39 +00:00
return Rectangle<int>(x, y, w, h).toFloat().transformedBy(AffineTransform::scale(getScaleFactor())).toNearestInt();
}
ImageButton* ObxdAudioProcessorEditor::addMenuButton (int x, int y, int d, String imgName)
2020-04-24 06:15:00 +00:00
{
2021-09-01 08:38:39 +00:00
ImageMenu* imageButton = new ImageMenu(imgName, &processor);
imageButtons.add (imageButton);
2020-04-24 06:15:00 +00:00
imageButton->setBounds (x, y, d, d);
2021-09-01 08:38:39 +00:00
2020-07-20 09:13:51 +00:00
imageButton->onClick = [this](){
ImageButton *imageButton = this->imageButtons[0];
auto x = imageButton->getScreenX();
auto y = imageButton->getScreenY();
auto dx = imageButton->getWidth();
auto pos = Point<int> (x, y + dx);
resultFromMenu (pos);
};
2020-04-24 06:15:00 +00:00
addAndMakeVisible (imageButton);
2021-09-01 08:38:39 +00:00
return imageButton;
2020-04-24 06:15:00 +00:00
}
void ObxdAudioProcessorEditor::rebuildComponents (ObxdAudioProcessor& ownerFilter)
2017-01-23 10:15:08 +00:00
{
skinFolder = ownerFilter.getCurrentSkinFolder();
2017-01-23 10:15:08 +00:00
ownerFilter.removeChangeListener (this);
2017-01-23 10:15:08 +00:00
// deleteAllChildren(); // WATCH OUT!
2017-01-23 10:15:08 +00:00
2021-09-01 08:38:39 +00:00
setSize (1440, 450);
ownerFilter.addChangeListener (this);
2017-01-23 10:15:08 +00:00
repaint();
2021-09-01 08:38:39 +00:00
2017-01-23 10:15:08 +00:00
}
2020-05-10 09:15:47 +00:00
void ObxdAudioProcessorEditor::createMenu ()
2020-04-24 06:15:00 +00:00
{
popupMenus.clear();
2020-05-10 09:15:47 +00:00
PopupMenu* menu = new PopupMenu();
2021-09-17 12:16:21 +00:00
//menu->setLookAndFeel(new CustomLookAndFeel(&this->processor));
2020-04-24 06:15:00 +00:00
PopupMenu progMenu;
PopupMenu bankMenu;
PopupMenu skinMenu;
PopupMenu fileMenu;
//PopupMenu viewMenu;
2021-05-19 18:09:59 +00:00
PopupMenu midiMenu;
2021-09-17 12:16:21 +00:00
menu->setLookAndFeel(&this->getLookAndFeel());
progMenu.setLookAndFeel(&this->getLookAndFeel());
bankMenu.setLookAndFeel(&this->getLookAndFeel());
skinMenu.setLookAndFeel(&this->getLookAndFeel());
fileMenu.setLookAndFeel(&this->getLookAndFeel());
midiMenu.setLookAndFeel(&this->getLookAndFeel());
2020-05-10 09:15:47 +00:00
skins = processor.getSkinFiles();
banks = processor.getBankFiles();
{
fileMenu.addItem(static_cast<int>(MenuAction::ImportPreset),
"Import Preset...",
true,
false);
fileMenu.addItem(static_cast<int>(MenuAction::ImportBank),
"Import Bank...",
true,
false);
fileMenu.addSeparator();
fileMenu.addItem(static_cast<int>(MenuAction::ExportPreset),
"Export Preset...",
true,
false);
fileMenu.addItem(static_cast<int>(MenuAction::ExportBank),
"Export Bank...",
true,
false);
fileMenu.addSeparator();
fileMenu.addItem(static_cast<int>(MenuAction::NewPreset),
"New Preset...",
true,//enableNewPresetOption,
false);
fileMenu.addItem(static_cast<int>(MenuAction::RenamePreset),
"Rename Preset...",
true,
false);
fileMenu.addItem(static_cast<int>(MenuAction::SavePreset),
"Save Preset...",
true,
false);
fileMenu.addItem(static_cast<int>(MenuAction::DeletePreset),
"Delete Preset...",
true,
false);
/*
fileMenu.addItem(static_cast<int>(MenuAction::DeleteBank),
"Delete Bank...",
true,
false);
*/
menu->addSubMenu("File", fileMenu);
}
2020-04-24 06:15:00 +00:00
{
for (int i = 0; i < processor.getNumPrograms(); ++i)
{
progMenu.addItem (i + progStart + 1,
processor.getProgramName (i),
true,
i == processor.getCurrentProgram());
}
2020-05-10 09:15:47 +00:00
menu->addSubMenu("Programs", progMenu);
2020-04-24 06:15:00 +00:00
}
menu->addItem(progStart + 1000, "Preset Bar", true, processor.showPresetBar);
2020-04-24 06:15:00 +00:00
{
const String currentBank = processor.getCurrentBankFile().getFileName();
for (int i = 0; i < banks.size(); ++i)
{
const File bank = banks.getUnchecked (i);
bankMenu.addItem (i + bankStart + 1,
bank.getFileNameWithoutExtension(),
true,
bank.getFileName() == currentBank);
}
2020-05-10 09:15:47 +00:00
menu->addSubMenu ("Banks", bankMenu);
2020-04-24 06:15:00 +00:00
}
2020-04-24 06:15:00 +00:00
{
for (int i = 0; i < skins.size(); ++i)
{
const File skin = skins.getUnchecked (i);
skinMenu.addItem (i + skinStart + 1,
skin.getFileName(),
true,
skin.getFileName() == skinFolder.getFileName());
}
2020-05-10 09:15:47 +00:00
menu->addSubMenu ("Themes", skinMenu);
2020-05-06 07:02:48 +00:00
// About // menu.addItem(1, String("Release ") + String(JucePlugin_VersionString).dropLastCharacters(2), false);
2020-04-24 06:15:00 +00:00
}
//menu->addSubMenu ("View", viewMenu);
2021-05-19 18:09:59 +00:00
menuMidiNum = progStart +2000;
createMidi(menuMidiNum, midiMenu);
menu->addSubMenu ("MIDI", midiMenu);
2020-05-10 09:15:47 +00:00
popupMenus.add (menu);
2021-09-01 08:38:39 +00:00
PopupMenu scaleMenu;
menuScaleNum =progStart +2000 + 3000;
scaleMenu.addItem(menuScaleNum, "1x", true, getScaleFactor() == 1.0f);
scaleMenu.addItem(menuScaleNum+1, "1.5x", true, getScaleFactor() == 1.5f);
scaleMenu.addItem(menuScaleNum+2, "2x", true, getScaleFactor() == 2.0f);
menu->addSubMenu("GUI Size", scaleMenu, true);
2021-09-06 15:49:10 +00:00
2021-09-07 07:54:47 +00:00
#ifdef LINUX
2021-09-06 15:49:10 +00:00
menu->addItem(1, String("Release ") + String(JucePlugin_VersionString).dropLastCharacters(2), false);
#endif
2021-09-07 07:54:47 +00:00
#if defined(JUCE_MAC) || defined(WIN32)
PopupMenu helpMenu;
2021-09-17 12:16:21 +00:00
helpMenu.setLookAndFeel(&this->getLookAndFeel());
String version = String("Release ") + String(JucePlugin_VersionString);//.dropLastCharacters(2);
helpMenu.addItem(menuScaleNum+4, "Manual", true);
2021-09-07 07:54:47 +00:00
helpMenu.addItem(menuScaleNum+3, version, false);
menu->addSubMenu("Help", helpMenu, true);
2021-09-06 15:49:10 +00:00
#endif
2020-05-10 09:15:47 +00:00
}
2021-05-19 18:09:59 +00:00
void ObxdAudioProcessorEditor::createMidi(int menuNo, PopupMenu &menuMidi) {
File midi_dir = processor.getMidiFolder();
File default_file = midi_dir.getChildFile("Default.xml");
if(default_file.exists()){
if (processor.currentMidiPath != default_file.getFullPathName()){
menuMidi.addItem(menuNo++, default_file.getFileNameWithoutExtension(), true, false);
} else {
menuMidi.addItem(menuNo++, default_file.getFileNameWithoutExtension(), true, true);
}
midiFiles.add(default_file.getFullPathName());
}
File custom_file = midi_dir.getChildFile("Custom.xml");
if(custom_file.exists()){
if (processor.currentMidiPath != custom_file.getFullPathName()){
menuMidi.addItem(menuNo++, custom_file.getFileNameWithoutExtension(), true, false);
} else {
menuMidi.addItem(menuNo++, custom_file.getFileNameWithoutExtension(), true, true);
}
midiFiles.add(custom_file.getFullPathName());
}
DirectoryIterator iter (midi_dir, true, "*.xml");
StringArray list;
while (iter.next())
{
list.add(iter.getFile().getFullPathName());
}
list.sort(true);
for (int i =0; i < list.size() ; i ++){
File f (list[i]);
if (f.getFileNameWithoutExtension() != "Default" && f.getFileNameWithoutExtension() != "Custom" && f.getFileNameWithoutExtension() != "Config") {
if (processor.currentMidiPath != f.getFullPathName()){
menuMidi.addItem(menuNo++, f.getFileNameWithoutExtension(), true, false);
} else {
menuMidi.addItem(menuNo++, f.getFileNameWithoutExtension(), true, true);
}
midiFiles.add(f.getFullPathName());
}
}
}
2020-05-10 09:15:47 +00:00
void ObxdAudioProcessorEditor::resultFromMenu (const Point<int> pos)
{
2021-05-20 17:12:33 +00:00
createMenu();
2020-05-10 09:15:47 +00:00
int result = popupMenus[0]->showAt (Rectangle<int> (pos.getX(), pos.getY(), 1, 1));
2020-04-24 06:15:00 +00:00
if (result >= (skinStart + 1) && result <= (skinStart + skins.size()))
{
result -= 1;
result -= skinStart;
const File newSkinFolder = skins.getUnchecked (result);
processor.setCurrentSkinFolder (newSkinFolder.getFileName());
//rebuildComponents (processor);
clean();
loadSkin (processor);
}
else if (result >= (bankStart + 1) && result <= (bankStart + banks.size()))
{
result -= 1;
result -= bankStart;
2020-05-10 09:15:47 +00:00
const File bankFile = banks.getUnchecked (result);
2020-04-24 06:15:00 +00:00
processor.loadFromFXBFile (bankFile);
//clean();
//loadSkin (processor); // Check this
2020-04-24 06:15:00 +00:00
}
else if (result >= (progStart + 1) && result <= (progStart + processor.getNumPrograms()))
{
result -= 1;
result -= progStart;
processor.setCurrentProgram (result);
//clean();
//loadSkin (processor); // Check this
2020-04-24 06:15:00 +00:00
}
else if (result < progStart){
MenuActionCallback(result);
}
2021-04-27 07:46:19 +00:00
else if (result == progStart + 1000){
2021-04-27 08:17:13 +00:00
processor.setShowPresetBar(!processor.getShowPresetBar());
2021-05-20 17:12:33 +00:00
//createMenu();
updatePresetBar(true);
2021-04-27 07:46:19 +00:00
}
2021-09-01 08:38:39 +00:00
else if (result >= menuScaleNum){
if (result ==menuScaleNum){
ScalableComponent::setScaleFactor(1.0f, isHighResolutionDisplay());
processor.setGuiSize(1);
}
else if (result == menuScaleNum+1){
ScalableComponent::setScaleFactor(1.5f, isHighResolutionDisplay());
processor.setGuiSize(2);
}
else if (result == menuScaleNum+2) {
ScalableComponent::setScaleFactor(2.0f, isHighResolutionDisplay());
processor.setGuiSize(4);
}
else if (result == menuScaleNum+4) {
File manualFile = processor.getDocumentFolder().getChildFile("OB-Xd Manual.pdf");
openInPdf(manualFile);
}
2021-09-01 08:38:39 +00:00
}
2021-05-19 18:09:59 +00:00
else if (result >= menuMidiNum){
unsigned int selected_idx = result - menuMidiNum;
if (selected_idx >= 0 && selected_idx < midiFiles.size()){
File f(midiFiles[selected_idx]);
if (f.exists()) {
processor.currentMidiPath = midiFiles[selected_idx];
processor.bindings.loadFile(f);
processor.updateConfig();
2021-05-20 17:12:33 +00:00
//createMenu();
2021-05-19 18:09:59 +00:00
}
}
}
2021-04-27 07:46:19 +00:00
}
2021-05-17 17:52:09 +00:00
void ObxdAudioProcessorEditor::updatePresetBar(bool resize){
2021-04-27 07:46:19 +00:00
DBG(" H: " << getHeight() <<" W:" <<getWidth() << " CW:"<<presetBar->getWidth() << " CH" <<presetBar->getHeight() << " CX:" <<presetBar->getX() << " CY: " <<presetBar->getY());
2021-05-17 17:52:09 +00:00
if (processor.getShowPresetBar()) {
if (resize) {
this->setSize(this->getWidth(), this->getHeight() + presetBar->getHeight());
2021-05-17 17:52:09 +00:00
}
2021-04-27 07:46:19 +00:00
presetBar->setVisible(true);
presetBar->update();
presetBar->setBounds((getWidth() - presetBar->getWidth()) / 2, getHeight() -presetBar->getHeight(), presetBar->getWidth(), presetBar->getHeight());
2021-04-27 07:46:19 +00:00
}
else if (presetBar->isVisible()) {
2021-05-17 17:52:09 +00:00
if (resize) {
this->setSize(this->getWidth(), this->getHeight() - presetBar->getHeight());
2021-05-17 17:52:09 +00:00
}
2021-04-27 07:46:19 +00:00
presetBar->setVisible(false);
}
2020-04-24 06:15:00 +00:00
}
void ObxdAudioProcessorEditor::MenuActionCallback(int action){
if (action == MenuAction::ImportBank)
{
fileChooser = std::make_unique<juce::FileChooser>("Import Bank (*.fxb)", juce::File(), "*.fxb", true);
if (fileChooser->browseForFileToOpen()) {
File result = fileChooser->getResult();
auto name = result.getFileName().replace("%20", " ");
auto file = processor.getBanksFolder().getChildFile(name);
if (result == file || result.copyFileTo(file)){
processor.loadFromFXBFile(file);
processor.scanAndUpdateBanks();
2021-05-20 17:12:33 +00:00
//createMenu();
}
}
};
if (action == MenuAction::ExportBank)
{
auto file = processor.getDocumentFolder().getChildFile("Banks");
FileChooser myChooser ("Export Bank (*.fxb)", file, "*.fxb", true);
if(myChooser.browseForFileToSave(true))
{
File result = myChooser.getResult();
String temp = result.getFullPathName();
if (!temp.endsWith(".fxb")) {
temp += ".fxb";
}
processor.saveBank(File(temp));
}
};
if (action == MenuAction::DeleteBank)
{
if(NativeMessageBox::showOkCancelBox(AlertWindow::NoIcon, "Delete Bank", "Delete current bank: " + processor.currentBank + "?")){
processor.deleteBank();
}
}
if (action == MenuAction::SavePreset)
{
auto presetName = processor.currentPreset;
if (presetName.isEmpty() )
{
processor.saveBank();
return;
}
processor.savePreset();
processor.saveBank();
}
if (action == MenuAction::NewPreset)
{
setPresetNameWindow = std::make_unique<SetPresetNameWindow>();
//preventBackgroundClick();
addAndMakeVisible(setPresetNameWindow.get());
resized();
auto callback = [this](int i, juce::String name)
{
if (i)
{
if (name.isNotEmpty())
{
processor.newPreset(name);
2021-05-20 17:12:33 +00:00
//createMenu();
}
}
setPresetNameWindow.reset();
//preventBackgroundClickComponent.reset();
};
setPresetNameWindow->callback = callback;
setPresetNameWindow->grabTextEditorFocus();
return;
}
if (action == MenuAction::RenamePreset)
{
setPresetNameWindow = std::make_unique<SetPresetNameWindow>();
//preventBackgroundClick();
setPresetNameWindow->setText(processor.getProgramName(processor.getCurrentProgram()));
addAndMakeVisible(setPresetNameWindow.get());
resized();
auto callback = [this](int i, juce::String name)
{
if (i)
{
if (name.isNotEmpty())
{
processor.changePresetName(name);
2021-05-20 17:12:33 +00:00
//createMenu();
}
}
setPresetNameWindow.reset();
//preventBackgroundClickComponent.reset();
};
setPresetNameWindow->callback = callback;
setPresetNameWindow->grabTextEditorFocus();
return;
}
if (action == MenuAction::DeletePreset)
{
if(NativeMessageBox::showOkCancelBox(AlertWindow::NoIcon, "Delete Preset", "Delete current preset " + processor.currentPreset + "?")){
processor.deletePreset();
2021-05-20 17:12:33 +00:00
//createMenu();
}
return;
}
if (action == MenuAction::ImportPreset)
{
DBG("Import Preset");
fileChooser = std::make_unique<juce::FileChooser>("Import Preset (*.fxp)", juce::File(), "*.fxp", true);
if (fileChooser->browseForFileToOpen()) {
File result = fileChooser->getResult();
//auto name = result.getFileName().replace("%20", " ");
//auto file = processor.getPresetsFolder().getChildFile(name);
DBG("Import Preset: " << result.getFileName());
//if (result == file || result.copyFileTo(file)){
processor.loadPreset(result);
2021-05-20 17:12:33 +00:00
//createMenu();
//}
}
};
if (action == MenuAction::ExportPreset)
{
auto file = processor.getPresetsFolder();
FileChooser myChooser ("Export Preset (*.fxp)", file, "*.fxp", true);
if(myChooser.browseForFileToSave(true))
{
File result = myChooser.getResult();
String temp = result.getFullPathName();
if (!temp.endsWith(".fxp")) {
temp += ".fxp";
}
processor.savePreset(File(temp));
}
};
}
void ObxdAudioProcessorEditor::deleteBank()
{
}
2020-12-14 18:27:00 +00:00
void ObxdAudioProcessorEditor::nextProgram() {
int cur = processor.getCurrentProgram() + 1;
if (cur == processor.getNumPrograms()) {
cur = 0;
}
2021-05-12 16:47:15 +00:00
processor.setCurrentProgram (cur, false);
needNotifytoHost = true;
countTimer = 0;
// Define for win and mac?
//clean();
//loadSkin (processor); // check
2020-12-14 18:27:00 +00:00
}
void ObxdAudioProcessorEditor::prevProgram() {
int cur = processor.getCurrentProgram() - 1;
if (cur < 0) {
cur = processor.getNumPrograms() - 1;
}
2021-05-12 16:47:15 +00:00
processor.setCurrentProgram (cur, false);
needNotifytoHost = true;
countTimer = 0;
//clean();
//loadSkin (processor);
2020-12-14 18:27:00 +00:00
}
2020-04-24 06:15:00 +00:00
void ObxdAudioProcessorEditor::buttonClicked (Button* b)
{
2020-07-20 09:13:51 +00:00
/*
2020-04-24 06:15:00 +00:00
auto imageButton = dynamic_cast<ImageButton*> (b);
if (imageButton == imageButtons[0])
{
auto x = imageButton->getScreenX();
auto y = imageButton->getScreenY();
auto dx = imageButton->getWidth();
auto pos = Point<int> (x, y + dx);
2020-05-10 09:15:47 +00:00
resultFromMenu (pos);
2020-07-20 09:13:51 +00:00
}*/
2020-07-16 08:14:56 +00:00
auto toggleButton = dynamic_cast<TooglableButton*> (b);
if (toggleButton == midiUnlearnButton){
2020-08-06 16:09:15 +00:00
if (midiUnlearnButton->getToggleState()){
2021-05-20 17:34:21 +00:00
countTimerForLed = 0;
2020-07-16 08:14:56 +00:00
processor.getMidiMap().reset();
processor.getMidiMap().set_default();
2020-07-16 18:10:39 +00:00
processor.sendChangeMessage();
2020-07-16 08:14:56 +00:00
}
}
2020-04-24 06:15:00 +00:00
}
2017-01-23 10:15:08 +00:00
//==============================================================================
void ObxdAudioProcessorEditor::updateFromHost() {
2020-05-10 09:15:47 +00:00
for (int i = 0; i < knobAttachments.size(); ++i)
{
2020-04-23 17:10:28 +00:00
knobAttachments[i]->updateToSlider();
}
/*
2020-05-10 09:15:47 +00:00
for (int i = 0; i < toggleAttachments.size(); ++i)
{
2020-04-23 17:10:28 +00:00
toggleAttachments[i]->updateToSlider();
}*/
2020-04-23 17:10:28 +00:00
2020-05-10 09:15:47 +00:00
for (int i = 0; i < buttonListAttachments.size(); ++i)
{
2020-04-23 17:10:28 +00:00
buttonListAttachments[i]->updateToSlider();
}
2020-05-10 09:15:47 +00:00
2020-07-16 18:10:39 +00:00
// Set to unlearn to false
2021-05-20 17:34:21 +00:00
//if ( midiUnlearnButton && midiUnlearnButton->getToggleState()) {
// Thread::sleep(500);
// midiUnlearnButton->setToggleState(false, NotificationType:: sendNotification);
//}
2020-07-16 18:10:39 +00:00
repaint();
2017-01-23 10:15:08 +00:00
}
void ObxdAudioProcessorEditor::changeListenerCallback (ChangeBroadcaster* source)
{
updateFromHost();
}
2017-01-23 10:15:08 +00:00
2020-04-24 06:15:00 +00:00
void ObxdAudioProcessorEditor::mouseUp (const MouseEvent& e)
2017-01-23 10:15:08 +00:00
{
if (e.mods.isRightButtonDown() || e.mods.isCommandDown())
{
2020-05-10 09:15:47 +00:00
resultFromMenu (e.getMouseDownScreenPosition());
2017-01-23 10:15:08 +00:00
}
}
2021-09-01 08:38:39 +00:00
void ObxdAudioProcessorEditor::handleAsyncUpdate() {
scaleFactorChanged();
repaint();
}
2017-01-23 10:15:08 +00:00
void ObxdAudioProcessorEditor::paint(Graphics& g)
{
2021-09-01 08:38:39 +00:00
const float newPhysicalPixelScaleFactor =
g.getInternalContext().getPhysicalPixelScaleFactor();
if (newPhysicalPixelScaleFactor != processor.physicalPixelScaleFactor)
{
processor.physicalPixelScaleFactor = newPhysicalPixelScaleFactor;
scaleFactorChanged();
2021-09-01 08:38:39 +00:00
}
g.fillAll (Colours::black);
2021-09-01 08:38:39 +00:00
// background gui
if(processor.showPresetBar){
g.drawImage(backgroundImage,
0, 0, getWidth(), getHeight() - 40,
0, 0, backgroundImage.getWidth(), backgroundImage.getHeight());
} else {
g.drawImage(backgroundImage,
0, 0, getWidth(), getHeight(),
0, 0, backgroundImage.getWidth(), backgroundImage.getHeight());
}
/*
2020-08-09 15:45:57 +00:00
#if JUCE_WINDOWS || JUCE_LINUX
2017-01-23 10:15:08 +00:00
const File mainFile(skinFolder.getChildFile("main.png"));
#else
const File mainFile(skinFolder.getChildFile("main@2x.png"));
#endif
2020-12-06 13:57:23 +00:00
if (!notLoadSkin && skinFolder.exists() && mainFile.exists())
2017-01-23 10:15:08 +00:00
{
const Image image = ImageCache::getFromFile(mainFile);
2020-08-09 15:45:57 +00:00
#if JUCE_WINDOWS || JUCE_LINUX
g.drawImage (image,
0, 0, image.getWidth(), image.getHeight(),
0, 0, image.getWidth(), image.getHeight());
#else
g.drawImage (image,
0, 0, image.getWidth()/2, image.getHeight()/2,
0, 0, image.getWidth(), image.getHeight());
#endif
2017-01-23 10:15:08 +00:00
}
else
{
const Image image = ImageCache::getFromMemory(BinaryData::main_png, BinaryData::main_pngSize);
// g.setImageResamplingQuality(Graphics::ResamplingQuality::highResamplingQuality);
2017-01-23 10:15:08 +00:00
g.drawImage (image,
0, 0, image.getWidth(), image.getHeight(),
0, 0, image.getWidth(), image.getHeight());
}
2021-09-01 08:38:39 +00:00
*/
2020-05-21 07:20:47 +00:00
}
2020-12-14 18:27:00 +00:00
2021-05-16 10:29:57 +00:00
bool ObxdAudioProcessorEditor::isInterestedInFileDrag(const StringArray& files)
{
StringArray extensions;
extensions.add(".fxp");
extensions.add(".fxb");
if (files.size() == 1) {
File file = File(files[0]);
String ext = file.getFileExtension().toLowerCase();
return file.existsAsFile() && extensions.contains(ext);
} else {
for (int q = 0; q < files.size(); q++) {
File file = File(files[q]);
String ext = file.getFileExtension().toLowerCase();
if (ext == ".fxb" || ext == ".fxp") {
return true;
}
}
}
return false;
}
void ObxdAudioProcessorEditor::filesDropped(const StringArray& files, int x, int y)
{
if (files.size() == 1) {
File file = File(files[0]);
String ext = file.getFileExtension().toLowerCase();
if (ext == ".fxp") {
processor.loadPreset(file);
2021-05-20 17:12:33 +00:00
//createMenu();
2021-05-16 10:29:57 +00:00
} else if (ext == ".fxb") {
auto name = file.getFileName().replace("%20", " ");
auto result = processor.getBanksFolder().getChildFile(name);
if (file.copyFileTo(result)){
processor.loadFromFXBFile(result);
processor.scanAndUpdateBanks();
2021-05-20 17:12:33 +00:00
//createMenu();
2021-05-16 10:29:57 +00:00
}
}
} else {
int i = processor.getCurrentProgram();
for (int q = 0; q < files.size(); q++) {
File file = File(files[q]);
String ext = file.getFileExtension().toLowerCase();
if (ext == ".fxp") {
processor.setCurrentProgram(i++);
processor.loadPreset(file);
}
2021-05-17 15:26:56 +00:00
if (i >=processor.getNumPrograms()){
i = 0;
}
2021-05-16 10:29:57 +00:00
}
processor.sendChangeMessage();
2021-05-20 17:12:33 +00:00
//createMenu();
2021-05-16 10:29:57 +00:00
}
}
const String ObxdAudioProcessorEditor::Action::panReset{ "panReset" };
2020-12-14 18:27:00 +00:00
/*
bool ObxdAudioProcessorEditor::keyPressed(const KeyPress & press) {
if (press.getKeyCode() == '+' || press.getKeyCode() == KeyPress::numberPadAdd)
{
nextProgram();
return false; // r+eturn true when the keypress was handled
}
if (press.getKeyCode() == '-' || press.getKeyCode() == KeyPress::numberPadSubtract)
{
prevProgram();
return false; // return true when the keypress was handled
}
return false; // return false if you don't handle the keypress
}*/