Skip to content

Commit

Permalink
Merge pull request #442 from FulopNandor/6_midiMonitor
Browse files Browse the repository at this point in the history
code cleanup for MidiMonitor
  • Loading branch information
asb2m10 authored Jul 29, 2024
2 parents 8fdafa3 + 32491d1 commit ddfc4e9
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
38 changes: 27 additions & 11 deletions Source/GlobalEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,25 @@
* Ugly but useful midi monitor to know if you are really sending/receiving something from the DX7
* If the midi is not configured this component wont show up
*
*/
#ifdef IMPLEMENT_MidiMonitor
class MidiMonitor : public Component {
SysexComm *midi;
Image light;
int imageHeight;
int imageHeight2;
int imageWidth;

SharedResourcePointer<DXLookNFeel> lookAndFeel;
public:
MidiMonitor(SysexComm *sysexComm) {
midi = sysexComm;
light = DXLookNFeel::getLookAndFeel()->imageLight;
light = lookAndFeel->imageLight;
imageHeight = light.getHeight();
imageHeight2 = imageHeight / 2;
imageWidth = light.getWidth();

TRACE("WARNING! This functionality is a candidate for deprecation/obsolescence!");
}

void paint(Graphics &g) {
Expand All @@ -47,24 +58,25 @@ class MidiMonitor : public Component {
g.setColour(Colours::white);

if ( midi->isInputActive() ) {
g.drawSingleLineText("DX7 IN", 17,14);
g.drawImage(light, 0, 3, 14, 14, 0, midi->inActivity ? 14 : 0, 14, 14);
g.drawSingleLineText("DX7 IN", 24, 18);
g.drawImage(light, 0, 0, imageWidth, imageHeight2, 0, midi->inActivity ? imageHeight2 : 0, imageWidth, imageHeight2);
midi->inActivity = false;
}

if ( midi->isOutputActive() ) {
g.drawSingleLineText("DX7 OUT", 17, 28);
g.drawImage(light, 0, 17, 14, 14, 0, midi->outActivity ? 14 : 0, 14, 14);
g.drawSingleLineText("DX7 OUT", 24, 36);
g.drawImage(light, 0, 18, imageWidth, imageHeight2, 0, midi->outActivity ? imageHeight2 : 0, imageWidth, imageHeight2);
midi->outActivity = false;
}
}
};*/
};
#endif //IMPLEMENT_MidiMonitor

class AboutBox : public DialogWindow {
public:
Image logo_png;
std::unique_ptr<juce::HyperlinkButton> dexed; // changed to std::unique_ptr from juce::ScopedPointer
std::unique_ptr<juce::HyperlinkButton> surge; // changed to std__unique_ptr from juce::ScopedPointer
std::unique_ptr<juce::HyperlinkButton> surge; // changed to std::unique_ptr from juce::ScopedPointer

AboutBox(Component *parent) : DialogWindow("About", Colour(0xFF000000), true),
dexed(std::make_unique<juce::HyperlinkButton>("https://asb2m10.github.io/dexed/", URL("https://asb2m10.github.io/dexed/"))),
Expand Down Expand Up @@ -706,9 +718,11 @@ void GlobalEditor::bind(DexedAudioProcessorEditor *edit) {

editor = edit;

//midiMonitor = new MidiMonitor(&(processor->sysexComm));
//addAndMakeVisible(midiMonitor);
//midiMonitor->setBounds(155, 21, 80, 45);
#ifdef IMPLEMENT_MidiMonitor
midiMonitor = std::make_unique<MidiMonitor>(&(processor->sysexComm));
addAndMakeVisible(*midiMonitor);
midiMonitor->setBounds(110, 10, 80, 45); //midiMonitor->setBounds(155, 21, 80, 45);
#endif //IMPLEMENT_MidiMonitor

repaint();
}
Expand All @@ -734,7 +748,9 @@ void GlobalEditor::updatePitchPos(int pos) {
void GlobalEditor::updateVu(float f) {
vuOutput->v = f;
vuOutput->repaint();
//midiMonitor->repaint();
#ifdef IMPLEMENT_MidiMonitor
midiMonitor->repaint();
#endif //IMPLEMENT_MidiMonitor
}

void GlobalEditor::setMonoState(bool state) {
Expand Down
9 changes: 8 additions & 1 deletion Source/GlobalEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include "DXComponents.h"
#include "AlgoDisplay.h"

#ifdef IMPLEMENT_MidiMonitor
#include "SysexComm.h"
#endif // IMPLEMENT_MidiMonitor

class DexedAudioProcessorEditor;
//[/Headers]

Expand Down Expand Up @@ -59,7 +63,10 @@ class GlobalEditor : public Component,

void setMonoState(bool state);
ProgramSelector *programs;
//std::unique_ptr<Component> midiMonitor;

#ifdef IMPLEMENT_MidiMonitor
std::unique_ptr<Component> midiMonitor;
#endif //IMPLEMENT_MidiMonitor

void mouseDown(const MouseEvent& e) override;
//[/UserMethods]
Expand Down
4 changes: 3 additions & 1 deletion Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,9 @@ void DexedAudioProcessor::handleIncomingMidiMessage(MidiInput* source, const Mid
if ( message.isActiveSense() )
return;

sysexComm.inActivity = true;
#ifdef IMPLEMENT_MidiMonitor
sysexComm.inActivity = true; // indicate to MidiMonitor that a MIDI messages (other than Active Sense) is received
#endif //IMPLEMENT_MidiMonitor

const uint8 *buf = message.getRawData();
int sz = message.getRawDataSize();
Expand Down
15 changes: 13 additions & 2 deletions Source/SysexComm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,23 @@ SysexComm::SysexComm() {
input = NULL;
output = NULL;
inputOutput = false;

#ifdef IMPLEMENT_MidiMonitor
inActivity = false;
outActivity = false;
#endif //IMPLEMENT_MidiMonitor
}

String SysexComm::getInput() {
return inputName;
}

bool SysexComm::setInput(String target) {
#ifndef IMPLEMENT_MidiMonitor
if ( JUCEApplication::isStandaloneApp() )
return true;

#endif

if ( input != NULL ) {
input->stop();
input = NULL;
Expand Down Expand Up @@ -132,7 +139,11 @@ void SysexComm::setChl(int chl) {
int SysexComm::send(const MidiMessage &message) {
if ( output == NULL )
return 2;
outActivity = true;

#ifdef IMPLEMENT_MidiMonitor
outActivity = true; // indicate to MidiMonitor that a MIDI message is going to be sent
#endif // IMPLEMENT_MidiMonitor

output->sendMessageNow(message);
return 0;
}
Expand Down
12 changes: 11 additions & 1 deletion Source/SysexComm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@

#include "../JuceLibraryCode/JuceHeader.h"

// If the macro ''IMPLEMENT_MidiMonitor'' is defined,
// then the class ''MidiMonitor'' and its related variables
// and invocations from other parts are implemented.
// If the macro is not defined the related source snippets are excluded.
// WARNING: this class and related variables and invocations
// are very likely candidates for deprecation / obsolescence,
// so it is NOT RECOMMENDED to define this macro!
//#define IMPLEMENT_MidiMonitor

class SysexComm {
std::unique_ptr<MidiInput> input;
std::unique_ptr<MidiOutput> output;
Expand All @@ -35,9 +44,10 @@ class SysexComm {
MidiBuffer noteOutput;
public :
MidiInputCallback *listener;
#ifdef IMPLEMENT_MidiMonitor
bool inActivity;
bool outActivity;

#endif //IMPLEMENT_MidiMonitor
SysexComm();

bool setInput(String name);
Expand Down

0 comments on commit ddfc4e9

Please sign in to comment.