Skip to content

Commit

Permalink
added buttons for wave selection
Browse files Browse the repository at this point in the history
  • Loading branch information
hsetlik committed Jun 4, 2021
1 parent cfd51f1 commit 8eb00cc
Show file tree
Hide file tree
Showing 20 changed files with 181 additions and 16 deletions.
Binary file modified .DS_Store
Binary file not shown.
14 changes: 14 additions & 0 deletions HexFm.jucer
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,24 @@
<FILE id="Zzs1UN" name="bothOn.png" compile="0" resource="1" file="PNGs/bothOn.png"/>
<FILE id="zHHq1p" name="downOff.png" compile="0" resource="1" file="PNGs/downOff.png"/>
<FILE id="Et71KY" name="downOn.png" compile="0" resource="1" file="PNGs/downOn.png"/>
<FILE id="wUv7MF" name="pulseOff.png" compile="0" resource="1" file="PNGs/pulseOff.png"/>
<FILE id="QaUc4e" name="pulseOn.png" compile="0" resource="1" file="PNGs/pulseOn.png"/>
<FILE id="mkbt0k" name="sawOff.png" compile="0" resource="1" file="PNGs/sawOff.png"/>
<FILE id="dMeHsK" name="sawOn.png" compile="0" resource="1" file="PNGs/sawOn.png"/>
<FILE id="cgcsvR" name="sineOff.png" compile="0" resource="1" file="PNGs/sineOff.png"/>
<FILE id="SUF6fX" name="sineOn.png" compile="0" resource="1" file="PNGs/sineOn.png"/>
<FILE id="Fb4Z1N" name="squareOff.png" compile="0" resource="1" file="PNGs/squareOff.png"/>
<FILE id="eDD67P" name="squareOn.png" compile="0" resource="1" file="PNGs/squareOn.png"/>
<FILE id="tkxCtz" name="triOff.png" compile="0" resource="1" file="PNGs/triOff.png"/>
<FILE id="ZU1PhI" name="triOn.png" compile="0" resource="1" file="PNGs/triOn.png"/>
<FILE id="KnNeWq" name="upOff.png" compile="0" resource="1" file="PNGs/upOff.png"/>
<FILE id="mPIM9v" name="upOn.png" compile="0" resource="1" file="PNGs/upOn.png"/>
</GROUP>
<GROUP id="{DFABB24D-7FEA-FB8A-D3A7-677009A3C90E}" name="Components">
<FILE id="MlHj7Y" name="WaveTypeSelector.cpp" compile="1" resource="0"
file="Source/WaveTypeSelector.cpp"/>
<FILE id="fpxmtz" name="WaveTypeSelector.h" compile="0" resource="0"
file="Source/WaveTypeSelector.h"/>
<FILE id="FGThsI" name="FilterPanel.cpp" compile="1" resource="0" file="Source/FilterPanel.cpp"/>
<FILE id="GRqHRw" name="FilterPanel.h" compile="0" resource="0" file="Source/FilterPanel.h"/>
<FILE id="h7YqHj" name="GlobalColor.h" compile="0" resource="0" file="Source/GlobalColor.h"/>
Expand Down
Binary file added PNGs/.DS_Store
Binary file not shown.
Binary file added PNGs/pulseOff.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 PNGs/pulseOn.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 PNGs/sawOff.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 PNGs/sawOn.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 PNGs/sineOff.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 PNGs/sineOn.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 PNGs/squareOff.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 PNGs/squareOn.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 PNGs/triOff.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 PNGs/triOn.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 modified Source/.DS_Store
Binary file not shown.
40 changes: 25 additions & 15 deletions Source/OperatorComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
OperatorComponent::OperatorComponent(int index, juce::AudioProcessorValueTreeState* pTree) :
opIndex(index),
envGraph(&delaySlider, &attackSlider, &holdSlider, &decaySlider, &sustainSlider, &releaseSlider),
waveButtons(index),
levelSlider(index),
ratioSlider(index),
ratioLabel(&ratioSlider.slider, ""),
Expand Down Expand Up @@ -80,6 +81,8 @@ panLabel(&panSlider, "")
sustainLabel.setLookAndFeel(&look2);
releaseLabel.setLookAndFeel(&look2);

addAndMakeVisible(&waveButtons);

panSlider.setVisible(false);
panSlider.setEnabled(false);
panLabel.setVisible(false);
Expand Down Expand Up @@ -139,21 +142,28 @@ void OperatorComponent::resized()
int n = getWidth() / 24;
auto fBounds = getBounds().toFloat().reduced(3.0f);
auto dN = fBounds.getWidth() / 48.0f;
delaySlider.setBounds(dN / 2, 50 * dN, 7.5 * dN, 7.5 * dN);
attackSlider.setBounds(8.5 * dN, 50 * dN, 7.5 * dN, 7.5 * dN);
holdSlider.setBounds(17 * dN, 50 * dN, 7.5 * dN, 7.5 * dN);
decaySlider.setBounds(25 * dN, 50 * dN, 7.5 * dN, 7.5 * dN);
sustainSlider.setBounds(33 * dN, 50 * dN, 7.5 * dN, 7.5 * dN);
releaseSlider.setBounds(41 * dN, 50 * dN, 7.5 * dN, 7.5 * dN);

delayLabel.setBounds(dN / 2, 56 * dN, 7.5 * dN, 3 * dN);
attackLabel.setBounds(8.5 * dN, 56 * dN, 7.5 * dN, 3 * dN);
holdLabel.setBounds(16.5 * dN, 56 * dN, 7.5 * dN, 3 * dN);
decayLabel.setBounds(24.5 * dN, 56 * dN, 7.5 * dN, 3 * dN);
sustainLabel.setBounds(32.5 * dN, 56 * dN, 7.5 * dN, 3 * dN);
releaseLabel.setBounds(40.5 * dN, 56 * dN, 7.5 * dN, 3 * dN);

envGraph.setBounds(n, 13 * n, 15 * n, 10 * n);
auto envSliderY = 62;
auto envLabelY = envSliderY + 6;
delaySlider.setBounds(dN / 2, envSliderY * dN, 7.5 * dN, 7.5 * dN);
attackSlider.setBounds(8.5 * dN, envSliderY * dN, 7.5 * dN, 7.5 * dN);
holdSlider.setBounds(17 * dN, envSliderY * dN, 7.5 * dN, 7.5 * dN);
decaySlider.setBounds(25 * dN, envSliderY * dN, 7.5 * dN, 7.5 * dN);
sustainSlider.setBounds(33 * dN, envSliderY * dN, 7.5 * dN, 7.5 * dN);
releaseSlider.setBounds(41 * dN, envSliderY * dN, 7.5 * dN, 7.5 * dN);

delayLabel.setBounds(dN / 2, envLabelY * dN, 7.5 * dN, 3 * dN);
attackLabel.setBounds(8.5 * dN, envLabelY * dN, 7.5 * dN, 3 * dN);
holdLabel.setBounds(16.5 * dN, envLabelY * dN, 7.5 * dN, 3 * dN);
decayLabel.setBounds(24.5 * dN, envLabelY * dN, 7.5 * dN, 3 * dN);
sustainLabel.setBounds(32.5 * dN, envLabelY * dN, 7.5 * dN, 3 * dN);
releaseLabel.setBounds(40.5 * dN, envLabelY * dN, 7.5 * dN, 3 * dN);

envGraph.setBounds(n, 19 * n, 15 * n, 10 * n);
/*
printf("n = %d\n", n);
printf("button width = %d\n", 3 * n);
*/
waveButtons.setBounds(n, 14 * n, 160, 40);

outputButton.setBounds(16 * n, 1.5 * n, 5.5 * n, 2.5 * n);
outputButton.changeWidthToFitText();
Expand Down
3 changes: 2 additions & 1 deletion Source/OperatorComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "SliderSubclasses.h"
#include "DAHDSRGraph.h"
#include "RGBColor.h"
#include "WaveTypeSelector.h"

//==============================================================================
/*
Expand Down Expand Up @@ -44,7 +45,7 @@ class OperatorComponent : public juce::Component, public juce::Button::Listener
int opIndex;
private:
DAHDSRGraph envGraph;
Color color;
WaveButtonSet waveButtons;
juce::Colour background;
LevelSlider levelSlider;
RatioSlider ratioSlider;
Expand Down
9 changes: 9 additions & 0 deletions Source/PluginProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ juce::AudioProcessorValueTreeState::ParameterLayout createLayout(int numOperator
layout.add(std::make_unique<juce::AudioParameterFloat>(decayId, decayName, timeRange2, 100.0f));
layout.add(std::make_unique<juce::AudioParameterFloat>(sustainId, sustainName, 0.0f, 1.0f , 0.6f));
layout.add(std::make_unique<juce::AudioParameterFloat>(releaseId, releaseName, timeRange2, 40.0f));
//operator wave types
juce::StringArray waveTypes;
waveTypes.add("Sine");
waveTypes.add("Square");
waveTypes.add("Saw");
waveTypes.add("Triangle");
auto waveId = "waveParam" + iStr;
auto waveName = "Operator " + iStr + " wave";
layout.add(std::make_unique<juce::AudioParameterChoice>(waveId, waveName, waveTypes, 0));
//bools for modulation paths
for(int n = 0; n < numOperators; ++n)
{
Expand Down
52 changes: 52 additions & 0 deletions Source/WaveTypeSelector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
==============================================================================
WaveTypeSelector.cpp
Created: 4 Jun 2021 8:44:02am
Author: Hayden Setlik
==============================================================================
*/

#include "WaveTypeSelector.h"

ImageToggle::ImageToggle(juce::Image on, juce::Image off) : onImg(on), offImg(off)
{
setClickingTogglesState(true);
}

void ImageToggle::paintButton(juce::Graphics &g, bool down, bool highlighted)
{
auto image = (getToggleState()) ? onImg : offImg;
auto fBounds = getLocalBounds();
g.drawImageAt(image, fBounds.getX(), fBounds.getY());
}
//==============================================================================

WaveButtonSet::WaveButtonSet(int opIndex) :
sineButton(ImageToggle::getForWave(Sine, true), ImageToggle::getForWave(Sine, false)),
squareButton(ImageToggle::getForWave(Square, true), ImageToggle::getForWave(Square, false)),
sawButton(ImageToggle::getForWave(Saw, true), ImageToggle::getForWave(Saw, false)),
triButton(ImageToggle::getForWave(Tri, true), ImageToggle::getForWave(Tri, false))
{
addAndMakeVisible(&sineButton);
addAndMakeVisible(&squareButton);
addAndMakeVisible(&sawButton);
addAndMakeVisible(&triButton);
int radioNum = 60 + opIndex;
sineButton.setRadioGroupId(radioNum);
squareButton.setRadioGroupId(radioNum);
sawButton.setRadioGroupId(radioNum);
triButton.setRadioGroupId(radioNum);
}

void WaveButtonSet::resized()
{
auto bounds = getLocalBounds();
auto dX = bounds.getWidth() / 4;
sineButton.setBounds(bounds.removeFromLeft(dX));
squareButton.setBounds(bounds.removeFromLeft(dX));
sawButton.setBounds(bounds.removeFromLeft(dX));
triButton.setBounds(bounds);
}

71 changes: 71 additions & 0 deletions Source/WaveTypeSelector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
==============================================================================
WaveTypeSelector.h
Created: 4 Jun 2021 8:44:02am
Author: Hayden Setlik
==============================================================================
*/

#pragma once
#include "RGBColor.h"
#include "GlobalColor.h"
#include "WavetableProcessor.h"

class ImageToggle : public juce::ImageButton
{
public:
ImageToggle(juce::Image on, juce::Image off);
void paintButton(juce::Graphics &g, bool down, bool highlighted) override;
static juce::Image getForWave(WaveType type, bool on)
{
switch(type)
{
case Sine:
{
if(on)
return juce::ImageCache::getFromMemory(BinaryData::sineOn_png, BinaryData::sineOn_pngSize);
else
return juce::ImageCache::getFromMemory(BinaryData::sineOff_png, BinaryData::sineOff_pngSize);
}
case Square:
{
if(on)
return juce::ImageCache::getFromMemory(BinaryData::squareOn_png, BinaryData::squareOn_pngSize);
else
return juce::ImageCache::getFromMemory(BinaryData::squareOff_png, BinaryData::squareOff_pngSize);
}
case Saw:
{
if(on)
return juce::ImageCache::getFromMemory(BinaryData::sawOn_png, BinaryData::sawOn_pngSize);
else
return juce::ImageCache::getFromMemory(BinaryData::sawOff_png, BinaryData::sawOff_pngSize);
}
case Tri:
{
if(on)
return juce::ImageCache::getFromMemory(BinaryData::triOn_png, BinaryData::triOn_pngSize);
else
return juce::ImageCache::getFromMemory(BinaryData::triOff_png, BinaryData::triOff_pngSize);
}
}
}
private:
juce::Image onImg;
juce::Image offImg;
};


class WaveButtonSet : public juce::Component
{
public:
WaveButtonSet(int opIndex);
void resized() override;
private:
ImageToggle sineButton;
ImageToggle squareButton;
ImageToggle sawButton;
ImageToggle triButton;
};
8 changes: 8 additions & 0 deletions Source/WavetableProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@
#include "WavetableData.h"
#define TABLESIZE 512

enum WaveType
{
Sine,
Square,
Saw,
Tri
};

class SineTableOscillator
{
public:
Expand Down

0 comments on commit 8eb00cc

Please sign in to comment.