Debian Codegraph @

plugin/drumgizmo_plugin.h

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /***************************************************************************
3 * drumgizmo_lv2.h
4 *
5 * Wed Mar 2 17:31:31 CET 2016
6 * Copyright 2016 Bent Bisballe Nyeng
7 * [email protected]
8 ****************************************************************************/
9
10 /*
11 * This file is part of DrumGizmo.
12 *
13 * DrumGizmo is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU Lesser General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * DrumGizmo is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public License
24 * along with DrumGizmo; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
26 */
27 #pragma once
28
29 #include <config.h>
30
31 #include <memory>
32
33 #ifdef LV2
34 #include <pluginlv2.h>
35 #endif
36
37 #ifdef VST
38 #include <pluginvst.h>
39 #endif
40
41 #include <drumgizmo.h>
42 #include <audioinputenginemidi.h>
43 #include <audiooutputengine.h>
44 #include <mainwindow.h>
45
46 #include <dggui/uitranslation.h>
47 #include <dggui/texturedbox.h>
48 #include <dggui/imagecache.h>
49 #include <dggui/image.h>
50
51 class DrumGizmoPlugin
52 #ifdef LV2
53 : public PluginLV2
54 #endif
55 #ifdef VST
56 : public PluginVST
57 #endif
58 {
59 public:
60 #ifdef VST
61 DrumGizmoPlugin(audioMasterCallback audioMaster);
62 #else
63 DrumGizmoPlugin();
64 #endif
65
66 void onFramesizeChange(size_t framesize) override;
67
68 void onSamplerateChange(float samplerate) override;
69
70 void onActiveChange(bool active) override;
71
72 std::string onStateSave() override;
73 void onStateRestore(const std::string& config) override;
74
75 size_t getNumberOfMidiInputs() override;
76 size_t getNumberOfMidiOutputs() override;
77 size_t getNumberOfAudioInputs() override;
78 size_t getNumberOfAudioOutputs() override;
79
80 // Functions used to set VST plugin information
81
82 std::string getId() override;
83 std::string getURI() override;
84 std::string getEffectName() override;
85 std::string getVendorString() override;
86 std::string getProductString() override;
87 std::string getHomepage() override;
88 PluginCategory getPluginCategory() override;
89
90 void process(size_t pos,
91 const std::vector<MidiEvent>& input_events,
92 std::vector<MidiEvent>& output_events,
93 const std::vector<const float*>& input_samples,
94 const std::vector<float*>& output_samples,
95 size_t count) override;
96
97 //
98 // Inline GUI
99 //
100 bool hasInlineGUI() override;
101 void onInlineRedraw(std::size_t width,
102 std::size_t max_height,
103 InlineDrawContext& context) override;
104
105 //
106 // GUI
107 //
108 bool hasGUI() override;
109 void* createWindow(void *parent) override;
110 void onDestroyWindow() override;
111 void onShowWindow() override;
112 void onHideWindow() override;
113 void onIdle() override;
114 void closeWindow() override;
115
116 private:
117
118 class Input
119 : public AudioInputEngineMidi
120 {
121 public:
122 Input(DrumGizmoPlugin& plugin);
123
124 bool init(const Instruments& instruments) override;
125
126 void setParm(const std::string& parm, const std::string& value) override;
127
128 bool start() override;
129 void stop() override;
130
131 void pre() override;
132 void run(size_t pos, size_t len, std::vector<event_t>& events) override;
133 void post() override;
134
135 bool isFreewheeling() const override;
136
137 bool loadMidiMap(const std::string& file, const Instruments& i) override;
138
139 protected:
140 DrumGizmoPlugin& plugin;
141 const Instruments* instruments{nullptr};
142 };
143
144 class Output
145 : public AudioOutputEngine
146 {
147 public:
148 Output(DrumGizmoPlugin& plugin);
149
150 bool init(const Channels& channels) override;
151
152 void setParm(const std::string& parm, const std::string& value) override;
153
154 bool start() override;
155 void stop() override;
156
157 void pre(size_t nsamples) override;
158 void run(int ch, sample_t *samples, size_t nsamples) override;
159 void post(size_t nsamples) override;
160
161 sample_t *getBuffer(int ch) const override;
162 std::size_t getBufferSize() const override;
163 std::size_t getSamplerate() const override;
164 bool isFreewheeling() const override;
165
166 protected:
167 DrumGizmoPlugin& plugin;
168 };
169
170 class ConfigStringIO
171 {
172 public:
173 ConfigStringIO(Settings& settings);
174
175 std::string get();
176 bool set(std::string config_string);
177 private:
178 Settings& settings;
179 };
180
181 Input input{*this};
182 const std::vector<MidiEvent>* input_events{nullptr};
183
184 Output output{*this};
185 const std::vector<float*>* output_samples{nullptr};
186
187 Settings settings;
188 ConfigStringIO config_string_io;
189 SettingsGetter settingsGetter{settings};
190
191 dggui::ImageCache imageCache;
192 dggui::TexturedBox box{imageCache, ":resources/progress.png",
193 0, 0, // atlas offset (x, y)
194 6, 1, 6, // dx1, dx2, dx3
195 11, 0, 0}; // dy1, dy2, dy3
196
197 dggui::TexturedBox bar_red{imageCache, ":resources/progress.png",
198 13, 0, // atlas offset (x, y)
199 2, 1, 2, // dx1, dx2, dx3
200 11, 0, 0}; // dy1, dy2, dy3
201
202 dggui::TexturedBox bar_green{imageCache, ":resources/progress.png",
203 18, 0, // atlas offset (x, y)
204 2, 1, 2, // dx1, dx2, dx3
205 11, 0, 0}; // dy1, dy2, dy3
206
207 dggui::TexturedBox bar_blue{imageCache, ":resources/progress.png",
208 23, 0, // atlas offset (x, y)
209 2, 1, 2, // dx1, dx2, dx3
210 11, 0, 0}; // dy1, dy2, dy3
211
212 std::shared_ptr<GUI::MainWindow> plugin_gui;
213 std::shared_ptr<DrumGizmo> drumgizmo;
214
215 std::uint32_t inlineDisplayBuffer[1024*1024];
216 dggui::Image inline_display_image{":resources/logo.png"};
217 bool inline_image_first_draw{true};
218
219 #ifdef WITH_NLS
220 dggui::UITranslation translation;
221 #endif // WITH_NLS
222 };