Krotos Modules 3
Loading...
Searching...
No Matches
krotos::GrainVisualiser Class Reference

A component to display the grains of the reformer engine. More...

#include <GrainVisualiser.h>

Inheritance diagram for krotos::GrainVisualiser:
krotos::ZoomableComponent

Public Types

enum  GrainRenderStyle { Compound = 0 , DotsWithLines , NUM_GRAIN_STYLES }
 Enumerate the sets of PNGs used to render grains. More...
 

Public Member Functions

 GrainVisualiser ()
 
 ~GrainVisualiser () override
 
void drawGrain (Graphics &graphicContext, Graphics &overlayContext, float x, float y, float diameter, float sprite, float envelope=0.f)
 Draw a grain blob into the grain display 2D.
 
void drawGrainPerspective (Graphics &graphicContext, Graphics &overlayContext, float x, float y, float z, float q, const AffineTransform &transform, float envelope=-1.f)
 Draw a grain blob into the grain display 3D.
 
void drawBackdropGradient (juce::Graphics &g)
 Draw a gradient for the display background.
 
void drawBackdrop (juce::Graphics &g)
 The backdrop is graphic which is drawn into the background of the display This method draws it into the supplied graphics context.
 
int calcBaseFrame (const float parallax, float &interFrame)
 Calculates which frame index into the background cache for a given parallax value.
 
int calcBaseFrame (float parallax)
 Calculates which frame index into the background cache for a given parallax value.
 
void drawInterpolatedBackground (juce::Graphics &g, float parallax)
 Draw the background from the backgound frames store The final image will be interpolated from the two nearest frames.
 
void drawDisplayBuffer (juce::Graphics &g)
 Draw the display buffer into a graphics context.
 
const AffineTransform makeParallaxRotationTransform (float parallax)
 Make an affine transform to rotate X & Z around the Y axis.
 
void paint (Graphics &g) override
 Paints in the grains display This method is called when the component is asked to re-paint itself This will be triggered either by the system - at random times of its choosing, or by timerCallback() in KwidgetGUI_XyPad calling m_grainVisualiser->repaint(); If sound data is not available, this call will paint in copy of the most recent legitimately rendered frame.
 
void updateBackgroundCacheFrame (SampleEngineShallow *sampleEngine, int index)
 Regenerate a frame in the background cache.
 
void requestBackgroundCacheRegeneration ()
 Sets a flag to request regeneration of the background cache.
 
void paintPlayingGrains (SampleEngineShallow *sampleEngine)
 Paint the grain display into the display buffer.
 
void drawBackgroundFrame (Graphics &graphicContext, Graphics &overlayContext, SampleEngineShallow *sampleEngine, float parallax)
 Draws all the grain display components - background.
 
void markBackgroundFramesDirty ()
 Sets the dirty flag true for every background frame.
 
void prepareToAddSampleEngines ()
 Called to indicate that you are about to start adding sample engines to the grain visualiser.
 
void finishedAddingSampleEngines ()
 Called to indicate that you have finished adding sample engines to the grain visualiser Checks to see if we need to regenerate the background cache. Simply detects a change in the number of active engines. We might add more detection methods as needs arise.
 
void shallowCopy (KrotosSampleOscillatorSound *sound)
 Set which sound is to be displayed.
 
void setPuckPosition (Point< float > position)
 
void setPerformMode (bool val)
 Set the visualiser into display mode.
 
void loadBinaryAssetGrainGraphics (GrainRenderStyle style)
 Loads the PNGs for display of grains from binary assets.
 
- Public Member Functions inherited from krotos::ZoomableComponent
 ZoomableComponent ()=default
 
 ~ZoomableComponent () override=default
 
void setHorizontalZoomFactor (float factor)
 
void setHorizontalZoomCenter (float center)
 
void setVerticalZoomFactor (float factor)
 
void setVerticalZoomCenter (float center)
 
void setHorizontalZoomFromRange (const Range< float > xr)
 
void SetTransformToFit (int width, int height)
 
float getHorizontalZoomFactor () const
 
float getHorizontalZoomCenter () const
 
float getVerticalZoomFactor () const
 
float getVerticalZoomCenter () const
 
Range< float > getHorizontalRange () const
 
Range< float > getVerticalRange () const
 

Static Public Attributes

static constexpr int ReformerMaxDisplayedInstances {4}
 

Private Attributes

float m_globalDisplayOpacity {0.f}
 
const float NUM_GLOBAL_FADE_UP_FRAMES {10.f}
 
const GrainRenderStyle DEFAULT_GRAIN_RENDER_STYLE {GrainRenderStyle::DotsWithLines}
 
bool m_performMode {false}
 
float m_parallaxFromPuck {0.f}
 
volatile std::atomic< float > m_puckPositionX
 
volatile std::atomic< float > m_puckPositionY
 
CriticalSection objectLock
 
float m_indicatorHue {0.f}
 
const float ROTATION_RANGE {0.7f}
 
const float PERSPECTIVE_SCALING_MIN {0.8f}
 
const float PERSPECTIVE_SCALING_MAX {1.0f}
 
const float ASPECT_RATIO {1.0f}
 
const float TWO_PI {6.28319f}
 
const float Z_SEPARATION_SCALING {-0.4f}
 
const float LEGACY_MODE_ALPHA_VALUE {0.55f}
 
const int NUM_BACKGROUND_FRAMES {12}
 
const float SMALLEST_FLOAT_VALUE {0.000001f}
 
const float BACKGROUND_INTERPOLATION_SPAN {(NUM_BACKGROUND_FRAMES - 1) - SMALLEST_FLOAT_VALUE}
 
bool m_requestBackgroundCacheRegeneration {false}
 
std::vector< KrotosImagem_backgroundCache
 
const int DISPLAY_WIDTH {240}
 
const int DISPLAY_HEIGHT {240}
 
float m_grainDiameter {1.f}
 
float m_overlayHue {0.f}
 
float m_overlayAlpha {0.f}
 
float m_grainAlpha {0.f}
 
float m_grainZ {0.f}
 
bool m_advancedGraphics {false}
 
Image m_backdropImage {Image(Image::ARGB, DISPLAY_WIDTH, DISPLAY_HEIGHT, true)}
 
Image m_displayBuffer {Image(Image::ARGB, DISPLAY_WIDTH, DISPLAY_HEIGHT, true)}
 
std::vector< KrotosImagem_grainImages
 
int m_redrawFrameIndex {-1}
 
std::vector< SampleEngineShallowm_shallowEngineArray
 
int m_numActiveEngines {0}
 

Additional Inherited Members

- Protected Member Functions inherited from krotos::ZoomableComponent
void drawNormalisedZoomedRect (Graphics &g, const Rectangle< float > &rect) const
 
void drawNormalisedZoomedRectLine (Graphics &g, const Rectangle< float > &rect) const
 
void drawZoomedRect (Graphics &g, const Rectangle< float > &rect) const
 
void drawNormalisedZoomedLine (Graphics &g, Line< float > line, float thickness) const
 
void drawZoomedLine (Graphics &g, const Line< float > &line, float thickness) const
 
void drawNormalisedZoomedText (Graphics &g, String text, Rectangle< float > bounds) const
 
void drawNormalisedZoomedPath (Graphics &g, const Path &path, float thickness)
 
void drawZoomedPath (Graphics &g, Path path, float thickness)
 
void drawNormalisedZoomedImage (Graphics &g, Image &image, const Rectangle< float > &bounds, bool fillAlphaChannelWithCurrentBrush=false)
 
void fillNormalisedZoomedEllipse (Graphics &g, const Rectangle< float > &bounds)
 
void drawNormalisedZoomedEllipse (Graphics &g, const Rectangle< float > &bounds)
 
void drawZoomedEllipse (Graphics &g, const Rectangle< float > &bounds)
 

Detailed Description

A component to display the grains of the reformer engine.

Member Enumeration Documentation

◆ GrainRenderStyle

Enumerate the sets of PNGs used to render grains.

Enumerator
Compound 
DotsWithLines 
NUM_GRAIN_STYLES 

Constructor & Destructor Documentation

◆ GrainVisualiser()

krotos::GrainVisualiser::GrainVisualiser ( )

◆ ~GrainVisualiser()

krotos::GrainVisualiser::~GrainVisualiser ( )
override

Member Function Documentation

◆ calcBaseFrame() [1/2]

int krotos::GrainVisualiser::calcBaseFrame ( const float parallax,
float & interFrame )
inline

Calculates which frame index into the background cache for a given parallax value.

Parameters
parallaxParallax value from 0 to 1
interFrameReturns a float representing the porportion of transition from baseframe to baseframe+1
Returns
Returns an integer representing which background frame the inter-frame interpolation starts at

◆ calcBaseFrame() [2/2]

int krotos::GrainVisualiser::calcBaseFrame ( float parallax)
inline

Calculates which frame index into the background cache for a given parallax value.

Parameters
parallaxParallax value from 0 to 1
Returns
Returns an integer representing which background frame the inter-frame interpolation starts at

◆ drawBackdrop()

void krotos::GrainVisualiser::drawBackdrop ( juce::Graphics & g)

The backdrop is graphic which is drawn into the background of the display This method draws it into the supplied graphics context.

Parameters
gGraphics context to draw into

◆ drawBackdropGradient()

void krotos::GrainVisualiser::drawBackdropGradient ( juce::Graphics & g)

Draw a gradient for the display background.

Parameters
gGraphics context to draw into

◆ drawBackgroundFrame()

void krotos::GrainVisualiser::drawBackgroundFrame ( Graphics & graphicContext,
Graphics & overlayContext,
SampleEngineShallow * sampleEngine,
float parallax )

Draws all the grain display components - background.

Parameters
gBgGraphics context to draw into
parallaxThe angle of rotation
enableLiveGrainsIf true, will render the scene without using the pre-rendered background frames

◆ drawDisplayBuffer()

void krotos::GrainVisualiser::drawDisplayBuffer ( juce::Graphics & g)

Draw the display buffer into a graphics context.

Parameters
gGraphics context to draw into

◆ drawGrain()

void krotos::GrainVisualiser::drawGrain ( Graphics & graphicContext,
Graphics & overlayContext,
float x,
float y,
float diameter,
float sprite,
float envelope = 0.f )

Draw a grain blob into the grain display 2D.

Parameters
gGraphics context to draw into
xX position, normalised 0->1
yY position, normalised 0->1
dDiameter of blob, normalised 0->1
spriteChoice of png to represent the grain, normalised 0->1
Choiceof png to represent the grain, normalised 0->1
envelopebulge/opacity of the grain, normalised 0->1

◆ drawGrainPerspective()

void krotos::GrainVisualiser::drawGrainPerspective ( Graphics & graphicContext,
Graphics & overlayContext,
float x,
float y,
float z,
float q,
const AffineTransform & transform,
float envelope = -1.f )

Draw a grain blob into the grain display 3D.

Parameters
gGraphics context to draw into
xX position, normalised 0->1
yY position, normalised 0->1
cZ position, normalised 0->1
transformAffineTransform to effect the rotation of the display about the y axis
envelopebulge/opacity of the grain, normalised 0->1. Set to -1 to disable

◆ drawInterpolatedBackground()

void krotos::GrainVisualiser::drawInterpolatedBackground ( juce::Graphics & g,
float parallax )

Draw the background from the backgound frames store The final image will be interpolated from the two nearest frames.

Parameters
gGraphics context to draw into
parallaxThe angle of rotation

◆ finishedAddingSampleEngines()

void krotos::GrainVisualiser::finishedAddingSampleEngines ( )
inline

Called to indicate that you have finished adding sample engines to the grain visualiser Checks to see if we need to regenerate the background cache. Simply detects a change in the number of active engines. We might add more detection methods as needs arise.

◆ loadBinaryAssetGrainGraphics()

void krotos::GrainVisualiser::loadBinaryAssetGrainGraphics ( GrainRenderStyle style)

Loads the PNGs for display of grains from binary assets.

Parameters
styleSets the set of graphics you wish to load

◆ makeParallaxRotationTransform()

const AffineTransform krotos::GrainVisualiser::makeParallaxRotationTransform ( float parallax)

Make an affine transform to rotate X & Z around the Y axis.

Parameters
parallaxA value from 0-1 representing the desired rotation
Returns
Returns an affine transfor representing the rotation

◆ markBackgroundFramesDirty()

void krotos::GrainVisualiser::markBackgroundFramesDirty ( )

Sets the dirty flag true for every background frame.

◆ paint()

void krotos::GrainVisualiser::paint ( Graphics & g)
override

Paints in the grains display This method is called when the component is asked to re-paint itself This will be triggered either by the system - at random times of its choosing, or by timerCallback() in KwidgetGUI_XyPad calling m_grainVisualiser->repaint(); If sound data is not available, this call will paint in copy of the most recent legitimately rendered frame.

Parameters
gGraphics context to draw into

◆ paintPlayingGrains()

void krotos::GrainVisualiser::paintPlayingGrains ( SampleEngineShallow * sampleEngine)

Paint the grain display into the display buffer.

Parameters
sampleEnginePointer to the Sample Engine we wish to display

◆ prepareToAddSampleEngines()

void krotos::GrainVisualiser::prepareToAddSampleEngines ( )
inline

Called to indicate that you are about to start adding sample engines to the grain visualiser.

◆ requestBackgroundCacheRegeneration()

void krotos::GrainVisualiser::requestBackgroundCacheRegeneration ( )
inline

Sets a flag to request regeneration of the background cache.

◆ setPerformMode()

void krotos::GrainVisualiser::setPerformMode ( bool val)
inline

Set the visualiser into display mode.

Parameters
valTrue for display mode on, false for off

◆ setPuckPosition()

void krotos::GrainVisualiser::setPuckPosition ( Point< float > position)
inline

◆ shallowCopy()

void krotos::GrainVisualiser::shallowCopy ( KrotosSampleOscillatorSound * sound)
inline

Set which sound is to be displayed.

Parameters
sound

◆ updateBackgroundCacheFrame()

void krotos::GrainVisualiser::updateBackgroundCacheFrame ( SampleEngineShallow * sampleEngine,
int index )

Regenerate a frame in the background cache.

Parameters
sampleEnginecontaining the grains to be displayed
indexto the background frame to regenerate

Member Data Documentation

◆ ASPECT_RATIO

const float krotos::GrainVisualiser::ASPECT_RATIO {1.0f}
private

◆ BACKGROUND_INTERPOLATION_SPAN

const float krotos::GrainVisualiser::BACKGROUND_INTERPOLATION_SPAN {(NUM_BACKGROUND_FRAMES - 1) - SMALLEST_FLOAT_VALUE}
private

◆ DEFAULT_GRAIN_RENDER_STYLE

const GrainRenderStyle krotos::GrainVisualiser::DEFAULT_GRAIN_RENDER_STYLE {GrainRenderStyle::DotsWithLines}
private

◆ DISPLAY_HEIGHT

const int krotos::GrainVisualiser::DISPLAY_HEIGHT {240}
private

◆ DISPLAY_WIDTH

const int krotos::GrainVisualiser::DISPLAY_WIDTH {240}
private

◆ LEGACY_MODE_ALPHA_VALUE

const float krotos::GrainVisualiser::LEGACY_MODE_ALPHA_VALUE {0.55f}
private

◆ m_advancedGraphics

bool krotos::GrainVisualiser::m_advancedGraphics {false}
private

◆ m_backdropImage

Image krotos::GrainVisualiser::m_backdropImage {Image(Image::ARGB, DISPLAY_WIDTH, DISPLAY_HEIGHT, true)}
private

◆ m_backgroundCache

std::vector<KrotosImage> krotos::GrainVisualiser::m_backgroundCache
private

◆ m_displayBuffer

Image krotos::GrainVisualiser::m_displayBuffer {Image(Image::ARGB, DISPLAY_WIDTH, DISPLAY_HEIGHT, true)}
private

◆ m_globalDisplayOpacity

float krotos::GrainVisualiser::m_globalDisplayOpacity {0.f}
private

◆ m_grainAlpha

float krotos::GrainVisualiser::m_grainAlpha {0.f}
private

◆ m_grainDiameter

float krotos::GrainVisualiser::m_grainDiameter {1.f}
private

◆ m_grainImages

std::vector<KrotosImage> krotos::GrainVisualiser::m_grainImages
private

◆ m_grainZ

float krotos::GrainVisualiser::m_grainZ {0.f}
private

◆ m_indicatorHue

float krotos::GrainVisualiser::m_indicatorHue {0.f}
private

◆ m_numActiveEngines

int krotos::GrainVisualiser::m_numActiveEngines {0}
private

◆ m_overlayAlpha

float krotos::GrainVisualiser::m_overlayAlpha {0.f}
private

◆ m_overlayHue

float krotos::GrainVisualiser::m_overlayHue {0.f}
private

◆ m_parallaxFromPuck

float krotos::GrainVisualiser::m_parallaxFromPuck {0.f}
private

◆ m_performMode

bool krotos::GrainVisualiser::m_performMode {false}
private

◆ m_puckPositionX

volatile std::atomic<float> krotos::GrainVisualiser::m_puckPositionX
private

◆ m_puckPositionY

volatile std::atomic<float> krotos::GrainVisualiser::m_puckPositionY
private

◆ m_redrawFrameIndex

int krotos::GrainVisualiser::m_redrawFrameIndex {-1}
private

◆ m_requestBackgroundCacheRegeneration

bool krotos::GrainVisualiser::m_requestBackgroundCacheRegeneration {false}
private

◆ m_shallowEngineArray

std::vector<SampleEngineShallow> krotos::GrainVisualiser::m_shallowEngineArray
private

◆ NUM_BACKGROUND_FRAMES

const int krotos::GrainVisualiser::NUM_BACKGROUND_FRAMES {12}
private

◆ NUM_GLOBAL_FADE_UP_FRAMES

const float krotos::GrainVisualiser::NUM_GLOBAL_FADE_UP_FRAMES {10.f}
private

◆ objectLock

CriticalSection krotos::GrainVisualiser::objectLock
private

◆ PERSPECTIVE_SCALING_MAX

const float krotos::GrainVisualiser::PERSPECTIVE_SCALING_MAX {1.0f}
private

◆ PERSPECTIVE_SCALING_MIN

const float krotos::GrainVisualiser::PERSPECTIVE_SCALING_MIN {0.8f}
private

◆ ReformerMaxDisplayedInstances

int krotos::GrainVisualiser::ReformerMaxDisplayedInstances {4}
staticconstexpr

◆ ROTATION_RANGE

const float krotos::GrainVisualiser::ROTATION_RANGE {0.7f}
private

◆ SMALLEST_FLOAT_VALUE

const float krotos::GrainVisualiser::SMALLEST_FLOAT_VALUE {0.000001f}
private

◆ TWO_PI

const float krotos::GrainVisualiser::TWO_PI {6.28319f}
private

◆ Z_SEPARATION_SCALING

const float krotos::GrainVisualiser::Z_SEPARATION_SCALING {-0.4f}
private

The documentation for this class was generated from the following files: