1 #include "bcdisplayinfo.h"
6 #include "pluginaclient.h"
7 #include "transportque.h"
13 class ReverseAudioConfig
21 class ReverseAudioEnabled : public BC_CheckBox
24 ReverseAudioEnabled(ReverseAudio *plugin,
31 class ReverseAudioWindow : public BC_Window
34 ReverseAudioWindow(ReverseAudio *plugin, int x, int y);
35 ~ReverseAudioWindow();
36 void create_objects();
39 ReverseAudioEnabled *enabled;
42 PLUGIN_THREAD_HEADER(ReverseAudio, ReverseAudioThread, ReverseAudioWindow)
44 class ReverseAudio : public PluginAClient
47 ReverseAudio(PluginServer *server);
50 PLUGIN_CLASS_MEMBERS(ReverseAudioConfig, ReverseAudioThread)
54 void save_data(KeyFrame *keyframe);
55 void read_data(KeyFrame *keyframe);
58 int process_buffer(int64_t size,
60 int64_t start_position,
63 int64_t input_position;
73 REGISTER_PLUGIN(ReverseAudio);
77 ReverseAudioConfig::ReverseAudioConfig()
86 ReverseAudioWindow::ReverseAudioWindow(ReverseAudio *plugin, int x, int y)
87 : BC_Window(plugin->gui_string,
98 this->plugin = plugin;
101 ReverseAudioWindow::~ReverseAudioWindow()
105 void ReverseAudioWindow::create_objects()
109 add_subwindow(enabled = new ReverseAudioEnabled(plugin,
116 WINDOW_CLOSE_EVENT(ReverseAudioWindow)
119 PLUGIN_THREAD_OBJECT(ReverseAudio, ReverseAudioThread, ReverseAudioWindow)
126 ReverseAudioEnabled::ReverseAudioEnabled(ReverseAudio *plugin,
131 plugin->config.enabled,
134 this->plugin = plugin;
137 int ReverseAudioEnabled::handle_event()
139 plugin->config.enabled = get_value();
140 plugin->send_configure_change();
152 ReverseAudio::ReverseAudio(PluginServer *server)
153 : PluginAClient(server)
155 PLUGIN_CONSTRUCTOR_MACRO
159 ReverseAudio::~ReverseAudio()
161 PLUGIN_DESTRUCTOR_MACRO
164 char* ReverseAudio::plugin_title() { return N_("Reverse audio"); }
165 int ReverseAudio::is_realtime() { return 1; }
167 #include "picon_png.h"
168 NEW_PICON_MACRO(ReverseAudio)
170 SHOW_GUI_MACRO(ReverseAudio, ReverseAudioThread)
172 RAISE_WINDOW_MACRO(ReverseAudio)
174 SET_STRING_MACRO(ReverseAudio);
177 int ReverseAudio::process_buffer(int64_t size,
179 int64_t start_position,
182 for(int i = 0; i < size; i += fragment_size)
184 fragment_size = size - i;
185 load_configuration();
188 read_samples(buffer + i,
193 for(int start = i, end = i + fragment_size - 1;
197 double temp = buffer[start];
198 buffer[start] = buffer[end];
203 read_samples(buffer + i,
208 if(get_direction() == PLAY_FORWARD)
209 start_position += fragment_size;
211 start_position -= fragment_size;
221 int ReverseAudio::load_configuration()
223 KeyFrame *prev_keyframe, *next_keyframe;
224 next_keyframe = get_next_keyframe(get_source_position());
225 prev_keyframe = get_prev_keyframe(get_source_position());
226 read_data(next_keyframe);
227 // Previous keyframe stays in config object.
228 read_data(prev_keyframe);
230 int64_t prev_position = edl_to_local(prev_keyframe->position);
231 int64_t next_position = edl_to_local(next_keyframe->position);
233 // printf("ReverseAudio::load_configuration 1 %lld %lld %lld %lld\n",
236 // prev_keyframe->position,
237 // next_keyframe->position);
238 // Defeat default keyframe
239 if(prev_position == 0 && next_position == 0)
241 next_position = prev_position = get_source_start();
244 // Get range to flip in requested rate
245 int64_t range_start = prev_position;
246 int64_t range_end = next_position;
248 // Between keyframe and edge of range or no keyframes
249 if(range_start == range_end)
251 // Between first keyframe and start of effect
252 if(get_source_position() >= get_source_start() &&
253 get_source_position() < range_start)
255 range_start = get_source_start();
258 // Between last keyframe and end of effect
259 if(get_source_position() >= range_start &&
260 get_source_position() < get_source_start() + get_total_len())
262 range_end = get_source_start() + get_total_len();
266 // Should never get here
271 // Convert start position to new direction
272 if(get_direction() == PLAY_FORWARD)
274 // Truncate next buffer to keyframe
275 if(range_end - get_source_position() < fragment_size)
276 fragment_size = range_end - get_source_position();
277 input_position = get_source_position() - range_start;
278 input_position = range_end - input_position - fragment_size;
282 if(get_source_position() - range_start < fragment_size)
283 fragment_size = get_source_position() - range_start;
284 input_position = range_end - get_source_position();
285 input_position = range_start + input_position + fragment_size;
287 // printf("ReverseAudio::load_configuration 20 start=%lld end=%lld current=%lld input=%lld\n",
290 // get_source_position(),
296 int ReverseAudio::load_defaults()
298 char directory[BCTEXTLEN];
299 // set the default directory
300 sprintf(directory, "%sreverseaudio.rc", BCASTDIR);
303 defaults = new BC_Hash(directory);
306 config.enabled = defaults->get("ENABLED", config.enabled);
310 int ReverseAudio::save_defaults()
312 defaults->update("ENABLED", config.enabled);
317 void ReverseAudio::save_data(KeyFrame *keyframe)
321 // cause data to be stored directly in text
322 output.set_shared_string(keyframe->data, MESSAGESIZE);
323 output.tag.set_title("REVERSEAUDIO");
324 output.tag.set_property("ENABLED", config.enabled);
326 output.terminate_string();
329 void ReverseAudio::read_data(KeyFrame *keyframe)
333 input.set_shared_string(keyframe->data, strlen(keyframe->data));
337 while(!input.read_tag())
339 if(input.tag.title_is("REVERSEAUDIO"))
341 config.enabled = input.tag.get_property("ENABLED", config.enabled);
346 void ReverseAudio::update_gui()
350 load_configuration();
351 thread->window->lock_window();
352 thread->window->enabled->update(config.enabled);
353 thread->window->unlock_window();