forked from matkatmusic/AudioFilePlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginEditor.h
149 lines (99 loc) · 4.41 KB
/
PluginEditor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
==============================================================================
This file contains the basic framework code for a JUCE plugin editor.
==============================================================================
*/
#pragma once
#include <JuceHeader.h>
#include "PluginProcessor.h"
using namespace juce;
inline Colour getUIColourIfAvailable (LookAndFeel_V4::ColourScheme::UIColour uiColour, Colour fallback = Colour (0xff4d4d4d)) noexcept
{
if (auto* v4 = dynamic_cast<LookAndFeel_V4*> (&LookAndFeel::getDefaultLookAndFeel()))
return v4->getCurrentColourScheme().getUIColour (uiColour);
return fallback;
}
class DemoThumbnailComp : public Component,
public ChangeListener,
public FileDragAndDropTarget,
public ChangeBroadcaster,
private ScrollBar::Listener,
private Timer
{
public:
DemoThumbnailComp (AudioFormatManager& formatManager,
Slider& slider,
AudioTransportSource& source);
~DemoThumbnailComp() override;
void setURL (const URL& url);
URL getLastDroppedFile() const noexcept;
void setZoomFactor (double amount);
void setRange (Range<double> newRange);
void setFollowsTransport (bool shouldFollow);
void paint (Graphics& g) override;
void resized() override;
void changeListenerCallback (ChangeBroadcaster*) override;
bool isInterestedInFileDrag (const StringArray& /*files*/) override;
void filesDropped (const StringArray& files, int /*x*/, int /*y*/) override;
void mouseDown (const MouseEvent& e) override;
void mouseDrag (const MouseEvent& e) override;
void mouseUp (const MouseEvent&) override;
void mouseWheelMove (const MouseEvent&, const MouseWheelDetails& wheel) override;
private:
AudioTransportSource& transportSource;
Slider& zoomSlider;
ScrollBar scrollbar { false };
AudioThumbnailCache thumbnailCache { 5 };
AudioThumbnail thumbnail;
Range<double> visibleRange;
bool isFollowingTransport = false;
URL lastFileDropped;
DrawableRectangle currentPositionMarker;
float timeToX (const double time) const;
double xToTime (const float x) const;
bool canMoveTransport() const noexcept;
void scrollBarMoved (ScrollBar* scrollBarThatHasMoved, double newRangeStart) override;
void timerCallback() override;
void updateCursorPosition();
};
class AudioFilePlayerAudioProcessorEditor : public juce::AudioProcessorEditor,
private FileBrowserListener,
private ChangeListener,
public Timer
{
public:
AudioFilePlayerAudioProcessorEditor(AudioFilePlayerAudioProcessor& p);
~AudioFilePlayerAudioProcessorEditor() override;
void paint (Graphics& g) override;
void resized() override;
void timerCallback() override;
private:
// if this PIP is running inside the demo runner, we'll use the shared device manager instead
AudioFilePlayerAudioProcessor& audioProcessor;
DirectoryContentsList directoryList;
FileTreeComponent fileTreeComp {directoryList};
Label explanation { {}, "Select an audio file in the treeview above, and this page will display its waveform, and let you play it.." };
/*
find the code that configures this
*/
// AudioTransportSource& transportSource;
// std::unique_ptr<AudioFormatReaderSource> currentAudioFileSource;
std::unique_ptr<DemoThumbnailComp> thumbnail;
Label zoomLabel { {}, "zoom:" };
Slider zoomSlider { Slider::LinearHorizontal, Slider::NoTextBox };
ToggleButton followTransportButton { "Follow Transport" };
TextButton startStopButton { "Load an audio file first..." };
ReferencedTransportSourceData::Ptr activeSource;
//==============================================================================
void startOrStop();
void updateFollowTransportState();
void selectionChanged() override;
void fileClicked (const File&, const MouseEvent&) override;
void fileDoubleClicked (const File&) override;
void browserRootChanged (const File&) override;
void changeListenerCallback (ChangeBroadcaster* source) override;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (AudioFilePlayerAudioProcessorEditor)
};
//==============================================================================
/**
*/