Skip to content

Commit

Permalink
replace current VU meter with a three-colored VU meter in main window
Browse files Browse the repository at this point in the history
  • Loading branch information
FulopNandor committed Apr 23, 2024
1 parent 3de1f99 commit e8554ea
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 18 deletions.
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.
23 changes: 22 additions & 1 deletion Source/DXComponents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ void VuMeter::paint(Graphics &g) {
if ( v <= 0 )
return;

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

if ( numBlocks > 46 )
Expand All @@ -334,6 +333,28 @@ void VuMeter::paint(Graphics &g) {
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);

if (v <= 0)
return;

int numBlocks = roundToInt(totalBlocks * v);

if (numBlocks > 46)
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
27 changes: 27 additions & 0 deletions Source/DXComponents.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,39 @@ 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;
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;

/// Ratio of length of the green+yellow area to total length
/// of the three-colored strip.
static constexpr float VU_0dB = ((float)(totalBlocks - numRedBlocks)) / ((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
30 changes: 18 additions & 12 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 Down Expand Up @@ -83,7 +83,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 +324,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 +397,12 @@ 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, 150, 24);


//[UserPreSize]
//[/UserPreSize]
Expand Down Expand Up @@ -450,7 +456,6 @@ GlobalEditor::~GlobalEditor()
algo = nullptr;
lcdDisplay = nullptr;
output = nullptr;
vuOutput = nullptr;
initButton = nullptr;
parmButton = nullptr;
cartButton = nullptr;
Expand All @@ -460,7 +465,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 @@ -730,8 +735,8 @@ void GlobalEditor::updatePitchPos(int pos) {
}

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

Expand Down Expand Up @@ -875,8 +880,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 +911,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 150 24"
class="vuMeterMain" params=""/>
</JUCER_COMPONENT>

END_JUCER_METADATA
Expand Down
5 changes: 3 additions & 2 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 Down Expand Up @@ -105,7 +105,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 +117,7 @@ class GlobalEditor : public Component,
std::unique_ptr<juce::Slider> tune;



//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalEditor)
};
Expand Down
8 changes: 5 additions & 3 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include "msfa/aligned_buf.h"
#include "msfa/fm_op_kernel.h"

#include "DXComponents.h"

#if JUCE_MSVC
#pragma comment (lib, "kernel32.lib")
#pragma comment (lib, "user32.lib")
Expand Down Expand Up @@ -293,9 +295,9 @@ void DexedAudioProcessor::processBlock(AudioSampleBuffer& buffer, MidiBuffer& mi
float f = *channelDatap;

// update VU meter
// The +1.0 outgoing sample value is scaled only to 0.8 on VU meter,
// to values exceeding 0.8 on VU meter indicate clippings/distortions.
float s = std::abs(f * 0.8);
// The abs values of outgoing sample values are scaled to the end of the last yellow block on VU meter,
// so outgoing abs values exceeding +1.0 will lie in the red region indicate clippings/distortions.
float s = std::abs(f * (VuMeterMain::VU_0dB));
const double decayFactor = 0.99992;
if (s > vuSignal)
vuSignal = s;
Expand Down

0 comments on commit e8554ea

Please sign in to comment.