Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reducing certain kind of distortion, implementation of dB-scaled VU meters and 200-300-400% GUI size selections #423

Closed
wants to merge 7 commits into from
4 changes: 4 additions & 0 deletions Dexed.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
file="Resources/ui/GlobalEditor_864x144.png"/>
<FILE id="GAIMQD" name="OperatorEditor_287x218.png" compile="0" resource="1"
file="Resources/ui/OperatorEditor_287x218.png"/>
<FILE id="kqdmAj" name="Meter3C_140x8.png" compile="0" resource="1"
file="Resources/ui/Meter3C_140x8.png"/>
<FILE id="c6DTJL" name="Meter3C_280x16.png" compile="0" resource="1"
file="Resources/ui/Meter3C_280x16.png"/>
</GROUP>
<GROUP id="{EA38D88A-6B79-E394-8B57-FA22D50C4D86}" name="Source">
<GROUP id="{1B64F271-8E56-F19A-FF63-094159E5EF7B}" name="dsp">
Expand Down
1 change: 1 addition & 0 deletions Resources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ juce_add_binary_data(DexedResources SOURCES
ui/Switch_64x64.png
ui/Switch_96x52.png
ui/SwitchLighted_48x26.png
ui/Meter3C_140x8.png
builtin_pgm.zip
)
Binary file added Resources/ui/Meter3C_140x8.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 Resources/ui/Meter3C_280x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 28 additions & 2 deletions Source/DXComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,42 @@ void VuMeter::paint(Graphics &g) {
if ( v <= 0 )
return;

const int totalBlocks = 46;
int numBlocks = roundToInt(totalBlocks * v);

if ( numBlocks > 46 )
if ( numBlocks > totalBlocks )
numBlocks = totalBlocks;
int brkpoint = numBlocks * 3 + 2;

g.drawImage(myStrip, 0, 0, brkpoint, 8, 0, 8, brkpoint, 8);
}


VuMeterMain::VuMeterMain() {
// load the three-colored strip
MemoryInputStream mis(BinaryData::Meter3C_140x8_png, BinaryData::Meter3C_140x8_pngSize, false);
strip3c = ImageFileFormat::loadFrom(mis);
}

void VuMeterMain::paint(Graphics& g) {
g.drawImage(strip3c, 0, 0, 140, 8, 0, 0, 140, 8);

// apply dB scale
v = 10 * log10(v);
v = (v + numNonRedBlocks) * one_per_totalBlocks;
if (v <= 0) {
//v = 0;
return;
}

int numBlocks = roundToInt(totalBlocks * v);

if (numBlocks > totalBlocks)
numBlocks = totalBlocks;
int brkpoint = numBlocks * 3 + 2;

g.drawImage(strip3c, 0, 0, brkpoint, 8, 0, 8, brkpoint, 8);
}

LcdDisplay::LcdDisplay() {
paramMsg = "DEXED " DEXED_VERSION;
}
Expand Down
35 changes: 35 additions & 0 deletions Source/DXComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,47 @@ class PitchEnvDisplay : public Component {
void paint(Graphics &g);
};

// Red-strip VU Meter for Operators' outputs
class VuMeter: public Component {
void paint(Graphics &g);
public :
/// Total number of blocks of the strips,
/// according to content of ''Meter3C_140x8_png''.
static const int totalBlocks = 46;

static constexpr float one_per_totalBlocks = 1.0F / totalBlocks;

// amplitude value corresponding to -(totalBlocks) dB
static constexpr float amp_46dB = 2.51189E-05;

float v;
};

// Green-yellow-red-colored VU Meter for Dexed's main output
class VuMeterMain : public VuMeter {
public:
VuMeterMain();
void paint(Graphics& g);

/// Number of red blocks on the three-colored strip,
/// according to the content of ''Meter3C_140x8_png''.
static const int numRedBlocks = 6;

/// Number of yellow blocks on the three-colored strip,
/// according to the content of ''Meter3C_140x8_png''.
static const int numYellowBlocks = 6;

static const int numNonRedBlocks = totalBlocks - numRedBlocks;

/// Ratio of length of the green+yellow area to total length
/// of the three-colored strip.
static constexpr float VU_0dB = ((float)numNonRedBlocks) / ((float)totalBlocks);

/// Image of a three-colored (green-yellow-red) strip,
/// loaded from ''Meter3C_140x8.png''.
Image strip3c;
};

class LcdDisplay : public Component {
public:
LcdDisplay();
Expand Down
4 changes: 3 additions & 1 deletion Source/DXLookNFeel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ DXLookNFeel::DXLookNFeel() {
}
}
}

#ifdef IMPLEMENT_DEADCODE_DXLookNFeel
// TODO: THIS IS DEAD CODE. NOBODY IS USING THIS.
forEachXmlChildElementWithTagName(*root, image, "image") {
String name = image->getStringAttribute("id", "");
Expand Down Expand Up @@ -156,6 +156,8 @@ DXLookNFeel::DXLookNFeel() {
continue;
}
}
TRACE("WARNING! Dead code snippet is implemented!");
#endif // IMPLEMENT_DEADCODE_DXLookNFeel
}

Typeface::Ptr DXLookNFeel::getTypefaceForFont(const Font &) {
Expand Down
7 changes: 7 additions & 0 deletions Source/DXLookNFeel.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

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

/// If the macro ''IMPLEMENT_DEADCODE_DXLookAndFeel'' is defined as any NONZERO value,
/// then a recently unused code snippet in constuctor ''DXLookNFeel::DXLookNFeel()''
/// in file ''DXLookNFeel.cpp'', is implemented.
/// Use 0 to exclude the related source snippets.
/// WARNING: this code snippet mentioned is very likely a candidate for deprecation/obsolescence.
#define IMPLEMENT_DEADCODE_DXLookNFeel 0

class LightedToggleButton : public ToggleButton {
public:
LightedToggleButton(const char*l) : ToggleButton(l) { }
Expand Down
10 changes: 10 additions & 0 deletions Source/EngineMkI.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,15 @@ class EngineMkI : public FmCore {
void compute_fb3(int32_t *output, FmOpParams *params, int32_t gain01, int32_t gain02, int32_t *fb_buf, int fb_shift);
};

/// Maximum absolute value of output amplitude of an operator of MkI Engine.
/// TODO: Its value _should_ _be_ derived from other constants used in this engine by some exact calculation
/// giving the maximum absolute value stored or added to ``output[i]`` in methods ``EngineMkI::compute()``,
/// ``EngineMkI::compute_pure()`` and ``EngineMkI::::compute_fb()``.
/// NOTE: this current value is still determined experimentally! 61613110
#define MAX_ABS_AMP_MKI_OP 6113110


/// Value of DC bias of output amplitude of an operator of MkI Engine.
#define DC_BIAS_MKI_OP 1069

#endif // ENGINEMKI_H_INCLUDED
12 changes: 0 additions & 12 deletions Source/EngineOpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,3 @@ void EngineOpl::render(int32_t *output, FmOpParams *params, int algorithm,
param.phase += param.freq << LG_N;
}
}












8 changes: 8 additions & 0 deletions Source/EngineOpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ class EngineOpl : public FmCore {
int32_t *fb_buf, int fb_gain, bool add);
};

/// Maximum absolute value of output amplitude of an operator of OPL Engine.
/// TODO: Its value _should_ _be_ derived from other constants used in this engine by some exact calculation
/// giving the maximum absolute value assigned or added to ``output[i]`` in methods ``EngineOpl::compute()``,
/// ``EngineOplFmOpKernel::compute_pure()`` and ``EngineOpl::compute_fb()``.
/// NOTE: this current value is still determined experimentally!
#define MAX_ABS_AMP_OPL_OP 61495214

/// Value of DC bias of output amplitude of an operator of OPL Engine.
#define DC_BIAS_OPL_OP 1069

#endif // ENGINEOPL_H_INCLUDED
54 changes: 35 additions & 19 deletions Source/GlobalEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
and re-saved.

Created with Projucer version: 6.0.7
Created with Projucer version: 7.0.7

------------------------------------------------------------------------------

Expand All @@ -31,14 +31,19 @@
* 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
*
*/
#if IMPLEMENT_MidiMonitor
class MidiMonitor : public Component {
SysexComm *midi;
Image light;

SharedResourcePointer<DXLookNFeel> lookAndFeel;
public:
MidiMonitor(SysexComm *sysexComm) {
midi = sysexComm;
light = DXLookNFeel::getLookAndFeel()->imageLight;
light = lookAndFeel->imageLight;

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

void paint(Graphics &g) {
Expand All @@ -58,13 +63,14 @@ class MidiMonitor : public Component {
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 All @@ -83,7 +89,7 @@ class AboutBox : public DialogWindow {
surge->setColour(HyperlinkButton::ColourIds::textColourId, Colour(0xFF4ea097));
surge->setJustificationType(Justification::left);
surge->setBounds(18, 458, getWidth() - 36, 30);

// create a new Component to hold ''dexed'' and ''surge'' as subcomponents
// and set this holder Component as the content component of the DialogWindow
Component* holder = new Component();
Expand Down Expand Up @@ -324,11 +330,11 @@ GlobalEditor::GlobalEditor ()

output->setBounds (157, 60, 34, 34);

vuOutput.reset (new VuMeter());
addAndMakeVisible (vuOutput.get());
vuOutput->setName ("vuOutput");
m_vuMeterMain.reset(new VuMeterMain());
addAndMakeVisible(m_vuMeterMain.get());
m_vuMeterMain->setName("id_VuMeterMain");

vuOutput->setBounds (6, 103, 140, 8);
m_vuMeterMain->setBounds(6, 103, 140, 8);

initButton.reset (new juce::TextButton ("initButton"));
addAndMakeVisible (initButton.get());
Expand Down Expand Up @@ -397,6 +403,11 @@ GlobalEditor::GlobalEditor ()

tune->setBounds (190, 9, 34, 34);

m_vuMeterMain.reset (new VuMeterMain());
addAndMakeVisible (m_vuMeterMain.get());
m_vuMeterMain->setName ("id_vuMeterMain");

m_vuMeterMain->setBounds(6, 103, 140, 8);

//[UserPreSize]
//[/UserPreSize]
Expand Down Expand Up @@ -450,7 +461,6 @@ GlobalEditor::~GlobalEditor()
algo = nullptr;
lcdDisplay = nullptr;
output = nullptr;
vuOutput = nullptr;
initButton = nullptr;
parmButton = nullptr;
cartButton = nullptr;
Expand All @@ -460,7 +470,7 @@ GlobalEditor::~GlobalEditor()
programSelector = nullptr;
aboutButton = nullptr;
tune = nullptr;

m_vuMeterMain = nullptr;

//[Destructor]. You can add your own custom destruction code here..
//[/Destructor]
Expand Down Expand Up @@ -704,9 +714,11 @@ void GlobalEditor::bind(DexedAudioProcessorEditor *edit) {

editor = edit;

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

repaint();
}
Expand All @@ -730,9 +742,12 @@ void GlobalEditor::updatePitchPos(int pos) {
}

void GlobalEditor::updateVu(float f) {
vuOutput->v = f;
vuOutput->repaint();
//midiMonitor->repaint();
m_vuMeterMain->v = f;
m_vuMeterMain->repaint();

#if IMPLEMENT_MidiMonitor
midiMonitor->repaint();
#endif
}

void GlobalEditor::setMonoState(bool state) {
Expand Down Expand Up @@ -875,8 +890,6 @@ BEGIN_JUCER_METADATA
explicitFocusOrder="0" pos="157 60 34 34" min="0.0" max="1.0"
int="0.0" style="RotaryVerticalDrag" textBoxPos="NoTextBox" textBoxEditable="0"
textBoxWidth="80" textBoxHeight="20" skewFactor="1.0" needsCallback="1"/>
<GENERICCOMPONENT name="vuOutput" id="dac75af912267f51" memberName="vuOutput" virtualName=""
explicitFocusOrder="0" pos="6 103 140 8" class="VuMeter" params=""/>
<TEXTBUTTON name="initButton" id="92b278163c42e21d" memberName="initButton"
virtualName="" explicitFocusOrder="0" pos="100 111 50 30" buttonText="INIT"
connectedEdges="0" needsCallback="1" radioGroupId="0"/>
Expand Down Expand Up @@ -908,6 +921,9 @@ BEGIN_JUCER_METADATA
explicitFocusOrder="0" pos="190 9 34 34" min="0.0" max="1.0"
int="0.0" style="RotaryVerticalDrag" textBoxPos="NoTextBox" textBoxEditable="0"
textBoxWidth="80" textBoxHeight="20" skewFactor="1.0" needsCallback="1"/>
<GENERICCOMPONENT name="id_vuMeterMain" id="c18ba85c0a5c7198" memberName="m_vuMeterMain"
virtualName="" explicitFocusOrder="0" pos="6 103 140 8"
class="vuMeterMain" params=""/>
</JUCER_COMPONENT>

END_JUCER_METADATA
Expand Down
13 changes: 10 additions & 3 deletions Source/GlobalEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
the "//[xyz]" and "//[/xyz]" sections will be retained when the file is loaded
and re-saved.

Created with Projucer version: 6.0.7
Created with Projucer version: 7.0.7

------------------------------------------------------------------------------

Expand All @@ -24,6 +24,9 @@
#include "PluginProcessor.h"
#include "DXComponents.h"
#include "AlgoDisplay.h"
#ifdef IMPLEMENT_MidiMonitor
#include "SysexComm.h"
#endif // IMPLEMENT_MidiMonitor

class DexedAudioProcessorEditor;
//[/Headers]
Expand Down Expand Up @@ -59,7 +62,10 @@ class GlobalEditor : public Component,

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

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

void mouseDown(const MouseEvent& e) override;
//[/UserMethods]
Expand Down Expand Up @@ -105,7 +111,7 @@ class GlobalEditor : public Component,
std::unique_ptr<juce::Slider> algo;
std::unique_ptr<LcdDisplay> lcdDisplay;
std::unique_ptr<juce::Slider> output;
std::unique_ptr<VuMeter> vuOutput;
std::unique_ptr<VuMeterMain> m_vuMeterMain;
std::unique_ptr<juce::TextButton> initButton;
std::unique_ptr<juce::TextButton> parmButton;
std::unique_ptr<juce::TextButton> cartButton;
Expand All @@ -117,6 +123,7 @@ class GlobalEditor : public Component,
std::unique_ptr<juce::Slider> tune;



//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalEditor)
};
Expand Down
Loading