Vital
Loading...
Searching...
No Matches
wavetable_playhead.h
Go to the documentation of this file.
1/*
2Summary:
3
4WavetablePlayhead represents a movable playhead line indicating a current position within a set of frames. Users can interact with it using mouse events to set a specific frame. The class supports customizable tick marks at regular intervals and notifies listeners whenever the playhead is moved.
5 */
6#pragma once
7
8#include "JuceHeader.h"
9
20public:
22 static constexpr int kBigLineSkip = 16;
23 static constexpr int kLineSkip = 4;
24
31 class Listener {
32 public:
33 virtual ~Listener() { }
34
39 virtual void playheadMoved(int new_position) = 0;
40 };
41
46 WavetablePlayhead(int num_positions);
47
52 int position() { return position_; }
53
60 void setPosition(int position);
61
65 void setPositionQuad();
66
71 void mouseDown(const MouseEvent& event) override;
72
77 void mouseDrag(const MouseEvent& event) override;
78
83 void mouseEvent(const MouseEvent& event);
84
89 void paintBackground(Graphics& g) override;
90
94 void resized() override;
95
100 void addListener(Listener* listener) { listeners_.push_back(listener); }
101
106 void setPadding(float padding) { padding_ = padding; setPositionQuad(); }
107
108protected:
110
111 std::vector<Listener*> listeners_;
112
113 float padding_;
117
118 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(WavetablePlayhead)
119};
A convenience class for a single quad rendered via OpenGL.
Definition open_gl_multi_quad.h:447
Base class for all synthesizer sections, providing UI layout, painting, and interaction logic.
Definition synth_section.h:193
A listener interface for objects interested in playhead position changes.
Definition wavetable_playhead.h:31
virtual ~Listener()
Definition wavetable_playhead.h:33
virtual void playheadMoved(int new_position)=0
Called when the playhead is moved to a new position.
A UI component representing a playhead position over a range of frames in a wavetable editor.
Definition wavetable_playhead.h:19
void mouseDrag(const MouseEvent &event) override
Handles mouse drag events, moving the playhead position accordingly.
Definition wavetable_playhead.cpp:37
void setPositionQuad()
Updates the visual position of the playhead quad based on the current position and size.
Definition wavetable_playhead.cpp:27
void resized() override
Called when the component is resized, updates the playhead position display.
Definition wavetable_playhead.cpp:66
static constexpr int kLineSkip
Definition wavetable_playhead.h:23
int num_positions_
Total number of positions (frames) available.
Definition wavetable_playhead.h:114
void paintBackground(Graphics &g) override
Paints the background ticks and line indicators for the playhead.
Definition wavetable_playhead.cpp:48
std::vector< Listener * > listeners_
Registered listeners to notify on position changes.
Definition wavetable_playhead.h:111
void mouseEvent(const MouseEvent &event)
Internal method for handling mouse events to change playhead position.
Definition wavetable_playhead.cpp:41
int drag_start_x_
Starting x position of the mouse when dragging.
Definition wavetable_playhead.h:116
WavetablePlayhead(int num_positions)
Constructs a WavetablePlayhead.
Definition wavetable_playhead.cpp:11
int position()
Gets the current playhead position.
Definition wavetable_playhead.h:52
void setPosition(int position)
Sets the playhead to a specific position.
Definition wavetable_playhead.cpp:17
static constexpr int kBigLineSkip
Used to determine which ticks are larger (every kBigLineSkip) and which are smaller (every kLineSkip)...
Definition wavetable_playhead.h:22
float padding_
Extra horizontal padding for the display area.
Definition wavetable_playhead.h:113
OpenGlQuad position_quad_
The visual quad representing the playhead line.
Definition wavetable_playhead.h:109
void addListener(Listener *listener)
Registers a listener interested in changes to the playhead position.
Definition wavetable_playhead.h:100
int position_
Current playhead position.
Definition wavetable_playhead.h:115
void mouseDown(const MouseEvent &event) override
Handles mouse down events for interaction.
Definition wavetable_playhead.cpp:33
void setPadding(float padding)
Sets the horizontal padding around the playhead display area.
Definition wavetable_playhead.h:106