2024-08-10 19:26:56 +00:00
# pragma once
2024-09-12 22:09:54 +00:00
# define VERSION_HINT 2
2024-08-10 19:26:56 +00:00
# include <JuceHeader.h>
2024-11-06 20:15:09 +00:00
# include "../components/EffectComponent.h"
# include "../components/SvgButton.h"
2024-08-13 13:55:30 +00:00
# include "../LookAndFeel.h"
2024-11-06 20:15:09 +00:00
# include "../components/SwitchButton.h"
2024-11-09 22:51:42 +00:00
# include "../audio/SmoothEffect.h"
2025-01-10 15:22:55 +00:00
# include "../audio/StereoEffect.h"
2024-08-10 19:26:56 +00:00
2025-01-07 18:28:55 +00:00
enum class ScreenOverlay : int {
2024-12-26 23:00:52 +00:00
Empty = 1 ,
Graticule = 2 ,
Smudged = 3 ,
SmudgedGraticule = 4 ,
2024-12-30 11:55:45 +00:00
# if SOSCI_FEATURES
2024-12-28 15:37:19 +00:00
Real = 5 ,
VectorDisplay = 6 ,
2024-12-30 11:55:45 +00:00
MAX = 6 ,
# else
MAX = 4 ,
# endif
2024-12-26 23:00:52 +00:00
} ;
2025-01-07 18:28:55 +00:00
class ScreenOverlayParameter : public IntParameter {
2024-12-26 23:00:52 +00:00
public :
2025-01-07 18:28:55 +00:00
ScreenOverlayParameter ( juce : : String name , juce : : String id , int versionHint , ScreenOverlay value ) : IntParameter ( name , id , versionHint , ( int ) value , 1 , ( int ) ScreenOverlay : : MAX ) { }
2024-12-26 23:00:52 +00:00
juce : : String getText ( float value , int maximumStringLength = 100 ) const override {
2025-01-07 18:28:55 +00:00
switch ( ( ScreenOverlay ) ( int ) getUnnormalisedValue ( value ) ) {
case ScreenOverlay : : Empty :
2024-12-26 23:00:52 +00:00
return " Empty " ;
2025-01-07 18:28:55 +00:00
case ScreenOverlay : : Graticule :
2024-12-26 23:00:52 +00:00
return " Graticule " ;
2025-01-07 18:28:55 +00:00
case ScreenOverlay : : Smudged :
2024-12-26 23:00:52 +00:00
return " Smudged " ;
2025-01-07 18:28:55 +00:00
case ScreenOverlay : : SmudgedGraticule :
2024-12-26 23:00:52 +00:00
return " Smudged Graticule " ;
2024-12-30 11:55:45 +00:00
# if SOSCI_FEATURES
2025-01-07 18:28:55 +00:00
case ScreenOverlay : : Real :
2024-12-26 23:00:52 +00:00
return " Real Oscilloscope " ;
2025-01-07 18:28:55 +00:00
case ScreenOverlay : : VectorDisplay :
2024-12-28 15:37:19 +00:00
return " Vector Display " ;
2024-12-30 11:55:45 +00:00
# endif
2024-12-26 23:00:52 +00:00
default :
return " Unknown " ;
}
}
float getValueForText ( const juce : : String & text ) const override {
int unnormalisedValue ;
if ( text = = " Empty " ) {
2025-01-07 18:28:55 +00:00
unnormalisedValue = ( int ) ScreenOverlay : : Empty ;
2024-12-26 23:00:52 +00:00
} else if ( text = = " Graticule " ) {
2025-01-07 18:28:55 +00:00
unnormalisedValue = ( int ) ScreenOverlay : : Graticule ;
2024-12-26 23:00:52 +00:00
} else if ( text = = " Smudged " ) {
2025-01-07 18:28:55 +00:00
unnormalisedValue = ( int ) ScreenOverlay : : Smudged ;
2024-12-26 23:00:52 +00:00
} else if ( text = = " Smudged Graticule " ) {
2025-01-07 18:28:55 +00:00
unnormalisedValue = ( int ) ScreenOverlay : : SmudgedGraticule ;
2024-12-30 11:55:45 +00:00
# if SOSCI_FEATURES
2024-12-26 23:00:52 +00:00
} else if ( text = = " Real Oscilloscope " ) {
2025-01-07 18:28:55 +00:00
unnormalisedValue = ( int ) ScreenOverlay : : Real ;
2024-12-28 15:37:19 +00:00
} else if ( text = = " Vector Display " ) {
2025-01-07 18:28:55 +00:00
unnormalisedValue = ( int ) ScreenOverlay : : VectorDisplay ;
2024-12-30 11:55:45 +00:00
# endif
2024-12-26 23:00:52 +00:00
} else {
2025-01-07 18:28:55 +00:00
unnormalisedValue = ( int ) ScreenOverlay : : Empty ;
2024-12-26 23:00:52 +00:00
}
return getNormalisedValue ( unnormalisedValue ) ;
}
void save ( juce : : XmlElement * xml ) {
2025-01-07 18:28:55 +00:00
xml - > setAttribute ( " screenOverlay " , getText ( getValue ( ) ) ) ;
2024-12-26 23:00:52 +00:00
}
void load ( juce : : XmlElement * xml ) {
2025-01-07 18:28:55 +00:00
setValueNotifyingHost ( getValueForText ( xml - > getStringAttribute ( " screenOverlay " ) ) ) ;
2024-12-26 23:00:52 +00:00
}
2024-12-28 15:37:19 +00:00
2024-12-30 11:55:45 +00:00
# if SOSCI_FEATURES
2024-12-28 15:37:19 +00:00
bool isRealisticDisplay ( ) {
2025-01-07 18:28:55 +00:00
ScreenOverlay type = ( ScreenOverlay ) ( int ) getValueUnnormalised ( ) ;
return type = = ScreenOverlay : : Real | | type = = ScreenOverlay : : VectorDisplay ;
2024-12-28 15:37:19 +00:00
}
2024-12-30 11:55:45 +00:00
# endif
2024-12-26 23:00:52 +00:00
} ;
2024-09-12 22:09:54 +00:00
class VisualiserParameters {
public :
2025-01-07 18:28:55 +00:00
ScreenOverlayParameter * screenOverlay = new ScreenOverlayParameter ( " Screen Overlay " , " screenOverlay " , VERSION_HINT , ScreenOverlay : : SmudgedGraticule ) ;
2024-11-17 12:18:30 +00:00
BooleanParameter * upsamplingEnabled = new BooleanParameter ( " Upsample Audio " , " upsamplingEnabled " , VERSION_HINT , true , " Upsamples the audio before visualising it to make it appear more realistic, at the expense of performance. " ) ;
BooleanParameter * sweepEnabled = new BooleanParameter ( " Sweep " , " sweepEnabled " , VERSION_HINT , false , " Plots the audio signal over time, sweeping from left to right " ) ;
2024-09-12 22:09:54 +00:00
BooleanParameter * visualiserFullScreen = new BooleanParameter ( " Visualiser Fullscreen " , " visualiserFullScreen " , VERSION_HINT , false , " Makes the software visualiser fullscreen. " ) ;
2025-01-10 12:41:34 +00:00
# if SOSCI_FEATURES
BooleanParameter * flipVertical = new BooleanParameter ( " Flip Vertical " , " flipVertical " , VERSION_HINT , false , " Flips the visualiser vertically. " ) ;
BooleanParameter * flipHorizontal = new BooleanParameter ( " Flip Horizontal " , " flipHorizontal " , VERSION_HINT , false , " Flips the visualiser horizontally. " ) ;
std : : shared_ptr < Effect > screenSaturationEffect = std : : make_shared < Effect > (
new EffectParameter (
" Screen Saturation " ,
" Controls how saturated the colours are on the oscilloscope screen. " ,
" screenSaturation " ,
VERSION_HINT , 1.0 , 0.0 , 5.0
)
) ;
2025-01-10 15:22:55 +00:00
std : : shared_ptr < StereoEffect > stereoEffectApplication = std : : make_shared < StereoEffect > ( ) ;
std : : shared_ptr < Effect > stereoEffect = std : : make_shared < Effect > (
stereoEffectApplication ,
new EffectParameter (
" Stereo " ,
" Turns mono audio that is uninteresting to visualise into stereo audio that is interesting to visualise. " ,
" stereo " ,
VERSION_HINT , 0.0 , 0.0 , 1.0
)
) ;
2025-01-10 12:41:34 +00:00
std : : shared_ptr < Effect > scaleEffect = std : : make_shared < Effect > (
[ this ] ( int index , OsciPoint input , const std : : vector < std : : atomic < double > > & values , double sampleRate ) {
input . scale ( values [ 0 ] . load ( ) , values [ 1 ] . load ( ) , 1.0 ) ;
return input ;
} , std : : vector < EffectParameter * > {
new EffectParameter (
" X Scale " ,
" Controls the horizontal scale of the oscilloscope display. " ,
" xScale " ,
VERSION_HINT , 1.0 , - 3.0 , 3.0
) ,
new EffectParameter (
" Y Scale " ,
" Controls the vertical scale of the oscilloscope display. " ,
" yScale " ,
VERSION_HINT , 1.0 , - 3.0 , 3.0
) ,
} ) ;
std : : shared_ptr < Effect > offsetEffect = std : : make_shared < Effect > (
[ this ] ( int index , OsciPoint input , const std : : vector < std : : atomic < double > > & values , double sampleRate ) {
input . translate ( values [ 0 ] . load ( ) , values [ 1 ] . load ( ) , 0.0 ) ;
return input ;
} , std : : vector < EffectParameter * > {
new EffectParameter (
" X Offset " ,
" Controls the horizontal position offset of the oscilloscope display. " ,
" xOffset " ,
VERSION_HINT , 0.0 , - 1.0 , 1.0
) ,
new EffectParameter (
" Y Offset " ,
" Controls the vertical position offset of the oscilloscope display. " ,
" yOffset " ,
VERSION_HINT , 0.0 , - 1.0 , 1.0
) ,
} ) ;
# endif
2024-09-12 22:09:54 +00:00
std : : shared_ptr < Effect > persistenceEffect = std : : make_shared < Effect > (
new EffectParameter (
" Persistence " ,
" Controls how long the light glows for on the oscilloscope display. " ,
" persistence " ,
VERSION_HINT , 0.5 , 0 , 6.0
)
) ;
std : : shared_ptr < Effect > hueEffect = std : : make_shared < Effect > (
new EffectParameter (
" Hue " ,
" Controls the hue/colour of the oscilloscope display. " ,
" hue " ,
VERSION_HINT , 125 , 0 , 359 , 1
)
) ;
std : : shared_ptr < Effect > intensityEffect = std : : make_shared < Effect > (
new EffectParameter (
" Intensity " ,
" Controls how bright the electron beam of the oscilloscope is. " ,
" intensity " ,
2024-11-17 12:18:30 +00:00
VERSION_HINT , 5.0 , 0.0 , 10.0
2024-09-12 22:09:54 +00:00
)
) ;
2025-01-05 22:54:02 +00:00
std : : shared_ptr < Effect > lineSaturationEffect = std : : make_shared < Effect > (
2024-09-29 18:46:35 +00:00
new EffectParameter (
2025-01-05 22:54:02 +00:00
" Line Saturation " ,
" Controls how saturated the colours are on the oscilloscope lines. " ,
" lineSaturation " ,
VERSION_HINT , 1.0 , 0.0 , 5.0
)
) ;
2024-09-29 19:36:16 +00:00
std : : shared_ptr < Effect > focusEffect = std : : make_shared < Effect > (
new EffectParameter (
" Focus " ,
" Controls how focused the electron beam of the oscilloscope is. " ,
" focus " ,
2025-01-05 22:54:02 +00:00
VERSION_HINT , 1.0 , 0.3 , 10.0
2024-09-29 19:36:16 +00:00
)
) ;
2024-11-06 20:15:09 +00:00
std : : shared_ptr < Effect > noiseEffect = std : : make_shared < Effect > (
new EffectParameter (
" Noise " ,
" Controls how much noise/grain is added to the oscilloscope display. " ,
" noise " ,
2024-11-17 12:18:30 +00:00
VERSION_HINT , 0.0 , 0.0 , 1.0
2024-11-06 20:15:09 +00:00
)
) ;
2024-11-09 21:37:20 +00:00
std : : shared_ptr < Effect > glowEffect = std : : make_shared < Effect > (
new EffectParameter (
" Glow " ,
" Controls how much the light glows on the oscilloscope display. " ,
" glow " ,
VERSION_HINT , 0.3 , 0.0 , 1.0
)
) ;
2024-12-26 23:00:52 +00:00
std : : shared_ptr < Effect > ambientEffect = std : : make_shared < Effect > (
new EffectParameter (
" Ambient Light " ,
" Controls how much ambient light is added to the oscilloscope display. " ,
" ambient " ,
2024-12-28 15:37:19 +00:00
VERSION_HINT , 0.7 , 0.0 , 5.0
2024-12-26 23:00:52 +00:00
)
) ;
2024-11-09 22:51:42 +00:00
std : : shared_ptr < Effect > smoothEffect = std : : make_shared < Effect > (
std : : make_shared < SmoothEffect > ( ) ,
new EffectParameter (
" Smoothing " ,
" This works as a low-pass frequency filter, effectively reducing the sample rate of the audio being visualised. " ,
" visualiserSmoothing " ,
VERSION_HINT , 0 , 0.0 , 1.0
)
) ;
2024-11-17 12:18:30 +00:00
std : : shared_ptr < Effect > sweepMsEffect = std : : make_shared < Effect > (
new EffectParameter (
" Sweep (ms) " ,
" The number of milliseconds it takes for the oscilloscope to sweep from left to right. " ,
" sweepMs " ,
2025-01-06 11:17:42 +00:00
VERSION_HINT , 10.0 , 0.0 , 1000.0
2025-01-03 16:37:36 +00:00
)
) ;
std : : shared_ptr < Effect > triggerValueEffect = std : : make_shared < Effect > (
new EffectParameter (
" Trigger Value " ,
" The trigger value sets the signal level that starts waveform capture to display a stable waveform. " ,
" triggerValue " ,
VERSION_HINT , 0.0 , - 1.0 , 1.0
2024-11-17 12:18:30 +00:00
)
) ;
2024-11-09 22:51:42 +00:00
2025-01-10 12:41:34 +00:00
std : : vector < std : : shared_ptr < Effect > > effects = {
persistenceEffect ,
hueEffect ,
intensityEffect ,
lineSaturationEffect ,
focusEffect ,
noiseEffect ,
glowEffect ,
ambientEffect ,
sweepMsEffect ,
triggerValueEffect ,
} ;
std : : vector < std : : shared_ptr < Effect > > audioEffects = {
smoothEffect ,
# if SOSCI_FEATURES
screenSaturationEffect ,
2025-01-10 15:22:55 +00:00
stereoEffect ,
2025-01-10 12:41:34 +00:00
scaleEffect ,
offsetEffect ,
# endif
} ;
std : : vector < BooleanParameter * > booleans = {
upsamplingEnabled ,
visualiserFullScreen ,
sweepEnabled ,
# if SOSCI_FEATURES
flipVertical ,
flipHorizontal ,
# endif
} ;
std : : vector < IntParameter * > integers = {
screenOverlay ,
} ;
2024-09-12 22:09:54 +00:00
} ;
2025-01-08 13:06:01 +00:00
class VisualiserSettings : public juce : : Component , public juce : : AudioProcessorParameter : : Listener {
2024-08-10 19:26:56 +00:00
public :
2024-09-22 17:49:58 +00:00
VisualiserSettings ( VisualiserParameters & , int numChannels = 2 ) ;
2024-08-10 19:26:56 +00:00
~ VisualiserSettings ( ) ;
2025-01-06 11:17:42 +00:00
void paint ( juce : : Graphics & g ) override ;
2024-08-10 19:26:56 +00:00
void resized ( ) override ;
2025-01-08 13:06:01 +00:00
void parameterValueChanged ( int parameterIndex , float newValue ) override ;
void parameterGestureChanged ( int parameterIndex , bool gestureIsStarting ) override ;
2024-10-22 21:25:09 +00:00
double getIntensity ( ) {
return parameters . intensityEffect - > getActualValue ( ) / 100 ;
}
double getPersistence ( ) {
return parameters . persistenceEffect - > getActualValue ( ) - 1.33 ;
}
double getHue ( ) {
return parameters . hueEffect - > getActualValue ( ) ;
}
2025-01-05 22:54:02 +00:00
double getLineSaturation ( ) {
return parameters . lineSaturationEffect - > getActualValue ( ) ;
}
2025-01-10 12:41:34 +00:00
# if SOSCI_FEATURES
2025-01-05 22:54:02 +00:00
double getScreenSaturation ( ) {
return parameters . screenSaturationEffect - > getActualValue ( ) ;
2024-10-22 21:25:09 +00:00
}
2025-01-10 12:41:34 +00:00
bool isFlippedVertical ( ) {
return parameters . flipVertical - > getBoolValue ( ) ;
}
bool isFlippedHorizontal ( ) {
return parameters . flipHorizontal - > getBoolValue ( ) ;
}
# endif
2024-10-22 21:25:09 +00:00
double getFocus ( ) {
return parameters . focusEffect - > getActualValue ( ) / 100 ;
}
2024-11-06 20:15:09 +00:00
double getNoise ( ) {
2025-01-05 22:54:02 +00:00
return parameters . noiseEffect - > getActualValue ( ) / 5 ;
2024-11-06 20:15:09 +00:00
}
2024-11-09 21:37:20 +00:00
double getGlow ( ) {
return parameters . glowEffect - > getActualValue ( ) * 3 ;
}
2024-12-26 23:00:52 +00:00
double getAmbient ( ) {
return parameters . ambientEffect - > getActualValue ( ) ;
2024-10-22 21:25:09 +00:00
}
2025-01-07 18:28:55 +00:00
ScreenOverlay getScreenOverlay ( ) {
return ( ScreenOverlay ) parameters . screenOverlay - > getValueUnnormalised ( ) ;
2024-10-22 21:25:09 +00:00
}
bool getUpsamplingEnabled ( ) {
return parameters . upsamplingEnabled - > getBoolValue ( ) ;
}
2025-01-03 16:37:36 +00:00
bool isSweepEnabled ( ) {
return parameters . sweepEnabled - > getBoolValue ( ) ;
}
double getSweepSeconds ( ) {
return parameters . sweepMsEffect - > getActualValue ( ) / 1000.0 ;
}
double getTriggerValue ( ) {
return parameters . triggerValueEffect - > getActualValue ( ) ;
}
2024-08-10 19:26:56 +00:00
2024-09-12 22:09:54 +00:00
VisualiserParameters & parameters ;
2024-09-22 17:49:58 +00:00
int numChannels ;
2024-09-12 22:09:54 +00:00
private :
EffectComponent intensity { * parameters . intensityEffect } ;
EffectComponent persistence { * parameters . persistenceEffect } ;
EffectComponent hue { * parameters . hueEffect } ;
2025-01-05 22:54:02 +00:00
EffectComponent lineSaturation { * parameters . lineSaturationEffect } ;
2024-09-29 19:36:16 +00:00
EffectComponent focus { * parameters . focusEffect } ;
2024-11-09 21:37:20 +00:00
EffectComponent noise { * parameters . noiseEffect } ;
EffectComponent glow { * parameters . glowEffect } ;
2024-12-26 23:00:52 +00:00
EffectComponent ambient { * parameters . ambientEffect } ;
2024-11-09 22:51:42 +00:00
EffectComponent smooth { * parameters . smoothEffect } ;
2024-11-17 12:18:30 +00:00
EffectComponent sweepMs { * parameters . sweepMsEffect } ;
2025-01-03 16:37:36 +00:00
EffectComponent triggerValue { * parameters . triggerValueEffect } ;
2024-08-13 13:55:30 +00:00
2025-01-07 18:28:55 +00:00
juce : : Label screenOverlayLabel { " Screen Overlay " , " Screen Overlay " } ;
juce : : ComboBox screenOverlay ;
2024-12-26 23:00:52 +00:00
2024-09-12 22:09:54 +00:00
jux : : SwitchButton upsamplingToggle { parameters . upsamplingEnabled } ;
2024-11-17 12:18:30 +00:00
jux : : SwitchButton sweepToggle { parameters . sweepEnabled } ;
2024-08-10 19:26:56 +00:00
2025-01-10 12:41:34 +00:00
# if SOSCI_FEATURES
EffectComponent screenSaturation { * parameters . screenSaturationEffect } ;
2025-01-10 15:22:55 +00:00
EffectComponent stereo { * parameters . stereoEffect } ;
2025-01-10 12:41:34 +00:00
EffectComponent xScale { * parameters . scaleEffect , 0 } ;
EffectComponent yScale { * parameters . scaleEffect , 1 } ;
EffectComponent xOffset { * parameters . offsetEffect , 0 } ;
EffectComponent yOffset { * parameters . offsetEffect , 1 } ;
jux : : SwitchButton flipVerticalToggle { parameters . flipVertical } ;
jux : : SwitchButton flipHorizontalToggle { parameters . flipHorizontal } ;
# endif
2024-08-10 19:26:56 +00:00
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR ( VisualiserSettings )
} ;
2024-08-13 13:55:30 +00:00
2025-01-06 11:17:42 +00:00
class ScrollableComponent : public juce : : Component {
public :
ScrollableComponent ( juce : : Component & component ) : component ( component ) {
addAndMakeVisible ( viewport ) ;
viewport . setViewedComponent ( & component , false ) ;
viewport . setScrollBarsShown ( true , false , true , false ) ;
}
void paint ( juce : : Graphics & g ) override {
g . fillAll ( Colours : : darker ) ;
}
void resized ( ) override {
viewport . setBounds ( getLocalBounds ( ) ) ;
}
private :
juce : : Viewport viewport ;
juce : : Component & component ;
} ;
2025-01-06 18:27:23 +00:00
class SettingsWindow : public juce : : DialogWindow {
2024-08-13 13:55:30 +00:00
public :
2025-01-06 18:27:23 +00:00
SettingsWindow ( juce : : String name , juce : : Component & component ) : juce : : DialogWindow ( name , Colours : : darker , true , true ) , component ( component ) {
setContentComponent ( & viewport ) ;
2024-12-15 19:23:31 +00:00
setResizable ( false , false ) ;
2025-01-06 18:27:23 +00:00
viewport . setColour ( juce : : ScrollBar : : trackColourId , juce : : Colours : : white ) ;
2025-01-01 16:38:58 +00:00
viewport . setViewedComponent ( & component , false ) ;
2025-01-03 16:37:36 +00:00
viewport . setScrollBarsShown ( true , false , true , false ) ;
2025-01-01 16:38:58 +00:00
setAlwaysOnTop ( true ) ;
2024-12-15 19:23:31 +00:00
}
2025-01-06 11:17:42 +00:00
2024-08-13 13:55:30 +00:00
void closeButtonPressed ( ) override {
setVisible ( false ) ;
}
2025-01-06 11:17:42 +00:00
2025-01-01 16:38:58 +00:00
private :
juce : : Viewport viewport ;
juce : : Component & component ;
2024-08-13 13:55:30 +00:00
} ;