4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef PLAYBACKENGINE_H
23 #define PLAYBACKENGINE_H
25 #include "arraylist.h"
26 #include "audiodevice.inc"
29 #include "channeldb.inc"
30 #include "condition.inc"
33 #include "mwindow.inc"
34 #include "maxchannels.h"
36 #include "tracking.inc"
37 #include "preferences.inc"
38 #include "renderengine.inc"
41 #include "transportque.h"
43 class PlaybackEngine : public Thread
46 PlaybackEngine(MWindow *mwindow, Canvas *output);
47 virtual ~PlaybackEngine();
49 void create_objects();
50 virtual int create_render_engine();
51 void delete_render_engine();
52 void arm_render_engine();
53 void start_render_engine();
54 void wait_render_engine();
56 void perform_change();
57 void sync_parameters(EDL *edl);
59 // Set wait_tracking for events that change the cursor location but
60 // be sure to unlock the windows
61 void interrupt_playback(int wait_tracking = 0);
62 // Get levels for tracking. Return 0 if no audio.
63 int get_output_levels(double *levels, long position);
64 int get_module_levels(ArrayList<double> *module_levels, long position);
65 // The MWindow starts the playback cursor loop
66 // The other windows start a slider loop
67 // For pausing only the cursor is run
68 virtual void init_cursor(int active);
69 virtual void stop_cursor();
70 virtual int brender_available(long position);
71 // For normal playback tracking and the cursor are started
72 virtual void init_tracking();
73 virtual void stop_tracking(double position);
74 virtual void init_meters();
75 // The playback cursor calls this to calculate the current tracking position
76 virtual double get_tracking_position();
77 // Reset the transport after completion
78 virtual void update_transport(int command, int paused);
79 // The render engines call this to update tracking variables in the playback engine.
80 void update_tracking(double position);
81 // Get the output channel table for the current device or 0 if none exists.
82 ChannelDB* get_channeldb();
85 void send_command(int command, EDL *edl, int wait_tracking, int use_inout);
86 void stop_playback(int wait);
87 void refresh_frame(int change_type, EDL *edl, int dir=1);
89 void update_preferences(Preferences *prefs);
91 // Maintain caches through console changes
92 CICache *audio_cache, *video_cache;
93 // Maintain playback cursor on GUI
95 // Tracking variables updated by render engines
96 double tracking_position;
97 // Not accurate until the first update_tracking, at which time
98 // tracking_active is incremented to 2.
100 // Lock access to tracking data
101 Mutex *tracking_lock;
102 // Lock access to renderengine between interrupt and deletion
103 Mutex *renderengine_lock;
104 // Block returns until tracking loop is finished
105 Condition *tracking_done;
106 // Pause the main loop for the PAUSE command
107 Condition *pause_lock;
108 // Wait until thread has started
109 Condition *start_lock;
115 // Copy of main preferences
116 Preferences *preferences;
118 int put_command(TransportCommand *command, int reset);
119 int transport_stop(int wait_tracking);
120 int transport_command(int command, int change_type=CHANGE_NONE,
121 EDL *new_edl=0, int use_inout=0);
123 Condition *input_lock, *output_lock;
124 // active command, stop command
125 TransportCommand *command, *stop_command;
126 // next command under construction, last sent command
127 TransportCommand *next_command, *sent_command;
130 RenderEngine *render_engine;
136 // General purpose debugging register