Vital
Loading...
Searching...
No Matches
WaveSourceEditor Class Reference

A graphical editor for manipulating a single-cycle waveform's sample values. More...

#include <wave_source_editor.h>

Inheritance diagram for WaveSourceEditor:
OpenGlLineRenderer AudioFileDropSource OpenGlComponent

Classes

class  Listener
 Interface for receiving notifications about waveform modifications. More...
 

Public Types

enum  WaveSourceMenu {
  kCancel = 0 , kFlipHorizontal , kFlipVertical , kClear ,
  kInitSaw
}
 Context menu actions for waveform editing. More...
 

Public Member Functions

 WaveSourceEditor (int size)
 Constructs a WaveSourceEditor with a given waveform size.
 
virtual ~WaveSourceEditor ()
 Destructor.
 
void paintBackground (Graphics &g) override
 Paints the background of the waveform editor.
 
void resized () override
 Adjusts layout and internal structures on component resize.
 
virtual void init (OpenGlWrapper &open_gl) override
 Initializes the OpenGL objects for drawing.
 
virtual void render (OpenGlWrapper &open_gl, bool animate) override
 Renders the waveform, grid lines, circles, and hover elements.
 
virtual void destroy (OpenGlWrapper &open_gl) override
 Cleans up the OpenGL resources used by the editor.
 
void mouseDown (const MouseEvent &e) override
 Handles a mouse down event to start editing or show the context menu.
 
void mouseUp (const MouseEvent &e) override
 Handles a mouse up event to finalize editing and notify listeners.
 
void mouseMove (const MouseEvent &e) override
 Handles a mouse move event to update the hover position.
 
void mouseDrag (const MouseEvent &e) override
 Handles a mouse drag event to continuously update waveform samples.
 
void mouseExit (const MouseEvent &e) override
 Handles a mouse exit event to clear the hover indication.
 
float valueAt (int index)
 Retrieves the waveform sample value at a given index.
 
void loadWaveform (float *waveform)
 Loads a complete waveform into the editor.
 
void addListener (Listener *listener)
 Adds a listener to be notified of value changes.
 
void setEditable (bool editable)
 Enables or disables editing of the waveform.
 
void setGrid (int horizontal, int vertical)
 Defines a grid overlay for snapping points.
 
void audioFileLoaded (const File &file) override
 Called when an audio file is dropped and loaded successfully.
 
void fileDragEnter (const StringArray &files, int x, int y) override
 Called when dragging audio files enters the component.
 
void fileDragExit (const StringArray &files) override
 Called when dragging audio files leaves the component.
 
void clear ()
 Clears the entire waveform to zero.
 
void flipVertical ()
 Flips the waveform vertically, inverting all sample values.
 
void flipHorizontal ()
 Flips the waveform horizontally, reversing its sample order.
 
- Public Member Functions inherited from OpenGlLineRenderer
 OpenGlLineRenderer (int num_points, bool loop=false)
 Constructs an OpenGlLineRenderer for a given number of points.
 
virtual ~OpenGlLineRenderer ()
 Destructor.
 
force_inline void setColor (Colour color)
 Sets the line color.
 
force_inline void setLineWidth (float width)
 Sets the line width in pixels.
 
force_inline void setBoost (float boost)
 Sets a global boost value affecting line thickness.
 
force_inline float boostLeftAt (int index) const
 Gets the left-side boost at a given point index.
 
force_inline float boostRightAt (int index) const
 Gets the right-side boost at a given point index.
 
force_inline float yAt (int index) const
 Gets the y-coordinate of a point at a given index.
 
force_inline float xAt (int index) const
 Gets the x-coordinate of a point at a given index.
 
force_inline void setBoostLeft (int index, float val)
 Sets the left-side boost for a point, marking data as dirty.
 
force_inline void setBoostRight (int index, float val)
 Sets the right-side boost for a point, marking data as dirty.
 
force_inline void setYAt (int index, float val)
 Sets the y-coordinate of a point, marking data as dirty.
 
force_inline void setXAt (int index, float val)
 Sets the x-coordinate of a point, marking data as dirty.
 
void setFillVertices (bool left)
 Sets fill vertices according to the current line and boost data.
 
void setLineVertices (bool left)
 Sets line vertices according to the current line and boost data.
 
force_inline void setFill (bool fill)
 Enables or disables filling below the line.
 
force_inline void setFillColor (Colour fill_color)
 Sets a uniform fill color if only one color is needed.
 
force_inline void setFillColors (Colour fill_color_from, Colour fill_color_to)
 Sets a gradient fill from one color to another.
 
force_inline void setFillCenter (float fill_center)
 Sets the vertical center for the fill area.
 
force_inline void setFit (bool fit)
 Enables fitting the line inside the available area.
 
force_inline void setBoostAmount (float boost_amount)
 Sets the boost amount that affects line thickness.
 
force_inline void setFillBoostAmount (float boost_amount)
 Sets the boost amount that affects fill thickness.
 
force_inline void setIndex (int index)
 Sets an index used for custom behavior (e.g., multiple line sets).
 
void boostLeftRange (float start, float end, int buffer_vertices, float min)
 Boosts left-side range of the line.
 
void boostRightRange (float start, float end, int buffer_vertices, float min)
 Boosts right-side range of the line.
 
void boostRange (float *boosts, float start, float end, int buffer_vertices, float min)
 Boosts a range for the given boost array.
 
void boostRange (vital::poly_float start, vital::poly_float end, int buffer_vertices, vital::poly_float min)
 Boosts left and right arrays using poly_float parameters.
 
void decayBoosts (vital::poly_float mult)
 Decays all boosts by a multiplicative factor, allowing animated damping.
 
void enableBackwardBoost (bool enable)
 Enables backward boost calculation for symmetrical line deformation.
 
force_inline int numPoints () const
 Gets the number of points in the line.
 
force_inline Colour color () const
 Gets the current line color.
 
void drawLines (OpenGlWrapper &open_gl, bool left)
 Draws the line and optional fill using OpenGL.
 
bool anyBoostValue ()
 Checks if any boost value is set.
 
- Public Member Functions inherited from OpenGlComponent
 OpenGlComponent (String name="")
 Constructs an OpenGlComponent.
 
virtual ~OpenGlComponent ()
 Destructor.
 
virtual void parentHierarchyChanged () override
 Called when the component's parent hierarchy changes.
 
void addRoundedCorners ()
 Adds rounded corners to the component's edges.
 
void addBottomRoundedCorners ()
 Adds rounded corners only at the bottom of the component.
 
void renderCorners (OpenGlWrapper &open_gl, bool animate, Colour color, float rounding)
 Renders the corner shapes using the given color and rounding amount.
 
void renderCorners (OpenGlWrapper &open_gl, bool animate)
 Renders corners with default body color and rounding.
 
void repaintBackground ()
 Requests a repaint of the component's background on the OpenGL layer.
 
Colour getBodyColor () const
 Retrieves the component's body color.
 
void setParent (const SynthSection *parent)
 Sets a pointer to the parent SynthSection for skin value lookups.
 
float findValue (Skin::ValueId value_id)
 Finds a float value from the skin associated with this component's parent.
 
void setSkinValues (const Skin &skin)
 Applies the skin overrides to this component's colors.
 
void setSkinOverride (Skin::SectionOverride skin_override)
 Sets a skin override to control the component's color scheme.
 
force_inline void checkGlError ()
 Checks for and asserts that there are no OpenGL errors.
 
void setBackgroundColor (const Colour &color)
 Sets the background color of the component for painting operations.
 
- Public Member Functions inherited from AudioFileDropSource
 AudioFileDropSource ()
 Constructs an AudioFileDropSource and registers basic audio formats.
 
bool isInterestedInFileDrag (const StringArray &files) override
 Checks if the drag operation includes exactly one file and if it matches supported audio formats.
 
void filesDropped (const StringArray &files, int x, int y) override
 Called when files are dropped onto the component.
 
void addListener (Listener *listener)
 Adds a listener to receive audio file load notifications.
 
String getExtensions ()
 Gets a wildcard pattern representing all supported audio formats.
 
AudioFormatManager & formatManager ()
 Provides access to the underlying AudioFormatManager.
 

Static Public Attributes

static constexpr int kMaxGridParts = WavetableComponentOverlay::kMaxGrid + 1
 
static constexpr int kNumCircles = kMaxGridParts * kMaxGridParts
 
- Static Public Attributes inherited from OpenGlLineRenderer
static constexpr int kLineFloatsPerVertex = 3
 Floats per vertex in the line data (x, y, and potentially others).
 
static constexpr int kFillFloatsPerVertex = 4
 Floats per vertex in the fill data (x, y, and boost value).
 
static constexpr int kLineVerticesPerPoint = 6
 Number of vertices per point in the line representation.
 
static constexpr int kFillVerticesPerPoint = 2
 Number of vertices per point in the fill representation.
 
static constexpr int kLineFloatsPerPoint = kLineVerticesPerPoint * kLineFloatsPerVertex
 Floats per point in the line data (6 vertices * 3 floats each).
 
static constexpr int kFillFloatsPerPoint = kFillVerticesPerPoint * kFillFloatsPerVertex
 Floats per point in the fill data (2 vertices * 4 floats each).
 

Additional Inherited Members

- Static Public Member Functions inherited from OpenGlComponent
static bool setViewPort (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
 Sets the OpenGL viewport to match a specified rectangle within a component.
 
static bool setViewPort (Component *component, OpenGlWrapper &open_gl)
 Convenience overload that sets the viewport for the entire component's local bounds.
 
static void setScissor (Component *component, OpenGlWrapper &open_gl)
 Sets the OpenGL scissor region to the entire component's local bounds.
 
static void setScissorBounds (Component *component, Rectangle< int > bounds, OpenGlWrapper &open_gl)
 Sets the OpenGL scissor region to a specified rectangle within a component.
 
static std::unique_ptr< OpenGLShaderProgram::Uniform > getUniform (const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name)
 Retrieves a uniform from the shader program if it exists.
 
static std::unique_ptr< OpenGLShaderProgram::Attribute > getAttribute (const OpenGlWrapper &open_gl, const OpenGLShaderProgram &program, const char *name)
 Retrieves an attribute from the shader program if it exists.
 
static String translateFragmentShader (const String &code)
 Translates a fragment shader code snippet to be compatible with the current GL version.
 
static String translateVertexShader (const String &code)
 Translates a vertex shader code snippet to be compatible with the current GL version.
 
- Protected Member Functions inherited from OpenGlComponent
bool setViewPort (OpenGlWrapper &open_gl)
 Sets the viewport for this component using the current OpenGlWrapper.
 
- Protected Attributes inherited from OpenGlComponent
std::unique_ptr< OpenGlCornerscorners_
 Optional corners for rounded edges.
 
bool only_bottom_corners_
 Flag to round only the bottom corners.
 
Colour background_color_
 The background color of the component.
 
Colour body_color_
 The body color of the component.
 
const SynthSectionparent_
 Pointer to parent SynthSection for skin lookups.
 
Skin::SectionOverride skin_override_
 Skin override for custom appearance.
 
const vital::StatusOutputnum_voices_readout_
 StatusOutput for voice count lookups.
 
- Protected Attributes inherited from AudioFileDropSource
AudioFormatManager format_manager_
 Manages and recognizes different audio file formats.
 

Detailed Description

A graphical editor for manipulating a single-cycle waveform's sample values.

The WaveSourceEditor displays a waveform as a line renderer and supports editing the waveform by clicking and dragging. It can snap points to a user-defined grid and provides optional context menu actions like clearing or flipping the waveform. It also supports drag-and-drop of audio files that are translated into waveform data.

Member Enumeration Documentation

◆ WaveSourceMenu

Context menu actions for waveform editing.

Enumerator
kCancel 

No operation.

kFlipHorizontal 

Flip the waveform horizontally.

kFlipVertical 

Flip the waveform vertically.

kClear 

Clear the entire waveform to zero.

kInitSaw 

Initialize waveform as a sawtooth wave (not currently implemented).

Constructor & Destructor Documentation

◆ WaveSourceEditor()

WaveSourceEditor::WaveSourceEditor ( int size)

Constructs a WaveSourceEditor with a given waveform size.

Parameters
sizeThe number of samples in the waveform cycle to be edited.

◆ ~WaveSourceEditor()

WaveSourceEditor::~WaveSourceEditor ( )
virtual

Destructor.

Member Function Documentation

◆ addListener()

void WaveSourceEditor::addListener ( Listener * listener)
inline

Adds a listener to be notified of value changes.

Parameters
listenerThe listener to add.

◆ audioFileLoaded()

void WaveSourceEditor::audioFileLoaded ( const File & file)
overridevirtual

Called when an audio file is dropped and loaded successfully.

Parameters
fileThe file loaded.

Implements AudioFileDropSource.

◆ clear()

void WaveSourceEditor::clear ( )

Clears the entire waveform to zero.

◆ destroy()

virtual void WaveSourceEditor::destroy ( OpenGlWrapper & open_gl)
inlineoverridevirtual

Cleans up the OpenGL resources used by the editor.

Parameters
open_glA wrapper containing the OpenGL context.

Reimplemented from OpenGlLineRenderer.

◆ fileDragEnter()

void WaveSourceEditor::fileDragEnter ( const StringArray & files,
int x,
int y )
override

Called when dragging audio files enters the component.

Parameters
filesThe files being dragged.
xThe x position of the drag.
yThe y position of the drag.

◆ fileDragExit()

void WaveSourceEditor::fileDragExit ( const StringArray & files)
override

Called when dragging audio files leaves the component.

Parameters
filesThe files that were being dragged.

◆ flipHorizontal()

void WaveSourceEditor::flipHorizontal ( )

Flips the waveform horizontally, reversing its sample order.

◆ flipVertical()

void WaveSourceEditor::flipVertical ( )

Flips the waveform vertically, inverting all sample values.

◆ init()

virtual void WaveSourceEditor::init ( OpenGlWrapper & open_gl)
inlineoverridevirtual

Initializes the OpenGL objects for drawing.

Parameters
open_glA wrapper containing the OpenGL context and shaders.

Reimplemented from OpenGlLineRenderer.

◆ loadWaveform()

void WaveSourceEditor::loadWaveform ( float * waveform)

Loads a complete waveform into the editor.

Parameters
waveformA pointer to an array of samples representing the waveform.

◆ mouseDown()

void WaveSourceEditor::mouseDown ( const MouseEvent & e)
override

Handles a mouse down event to start editing or show the context menu.

Parameters
eThe mouse event.

◆ mouseDrag()

void WaveSourceEditor::mouseDrag ( const MouseEvent & e)
override

Handles a mouse drag event to continuously update waveform samples.

Parameters
eThe mouse event.

◆ mouseExit()

void WaveSourceEditor::mouseExit ( const MouseEvent & e)
override

Handles a mouse exit event to clear the hover indication.

Parameters
eThe mouse event.

◆ mouseMove()

void WaveSourceEditor::mouseMove ( const MouseEvent & e)
override

Handles a mouse move event to update the hover position.

Parameters
eThe mouse event.

◆ mouseUp()

void WaveSourceEditor::mouseUp ( const MouseEvent & e)
override

Handles a mouse up event to finalize editing and notify listeners.

Parameters
eThe mouse event.

◆ paintBackground()

void WaveSourceEditor::paintBackground ( Graphics & g)
overridevirtual

Paints the background of the waveform editor.

Parameters
gGraphics context to draw into.

Reimplemented from OpenGlComponent.

◆ render()

virtual void WaveSourceEditor::render ( OpenGlWrapper & open_gl,
bool animate )
inlineoverridevirtual

Renders the waveform, grid lines, circles, and hover elements.

Parameters
open_glA wrapper containing the OpenGL context.
animateIndicates if this render is part of an animation.

Reimplemented from OpenGlLineRenderer.

◆ resized()

void WaveSourceEditor::resized ( )
overridevirtual

Adjusts layout and internal structures on component resize.

Reimplemented from OpenGlComponent.

◆ setEditable()

void WaveSourceEditor::setEditable ( bool editable)

Enables or disables editing of the waveform.

Parameters
editableIf true, the waveform can be edited by mouse.

◆ setGrid()

void WaveSourceEditor::setGrid ( int horizontal,
int vertical )

Defines a grid overlay for snapping points.

Parameters
horizontalThe number of vertical grid lines.
verticalThe number of horizontal grid lines.

◆ valueAt()

float WaveSourceEditor::valueAt ( int index)
inline

Retrieves the waveform sample value at a given index.

Parameters
indexThe sample index.
Returns
The sample value.

Member Data Documentation

◆ kMaxGridParts

int WaveSourceEditor::kMaxGridParts = WavetableComponentOverlay::kMaxGrid + 1
staticconstexpr

Maximum grid divisions as defined by the WavetableComponentOverlay class.

◆ kNumCircles

int WaveSourceEditor::kNumCircles = kMaxGridParts * kMaxGridParts
staticconstexpr

The number of circles for grid intersections.


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