1 #ifndef PLAYBACKENGINE_H
2 #define PLAYBACKENGINE_H
5 #include "audiodevice.inc"
8 #include "condition.inc"
9 #include "defaults.inc"
11 #include "mwindow.inc"
12 #include "maxchannels.h"
14 #include "tracking.inc"
15 #include "preferences.inc"
16 #include "renderengine.inc"
19 #include "transportque.inc"
20 #include "videodevice.inc"
22 class PlaybackEngine
: public Thread
25 PlaybackEngine(MWindow
*mwindow
, Canvas
*output
);
26 virtual ~PlaybackEngine();
29 virtual int create_render_engines();
30 void delete_render_engines();
31 void arm_render_engines();
32 void start_render_engines();
33 void wait_render_engines();
35 void perform_change();
36 void sync_parameters(EDL
*edl
);
37 // Set wait_tracking for events that change the cursor location but
38 // be sure to unlock the windows
39 void interrupt_playback(int wait_tracking
= 0);
40 // Get levels for tracking. Return 0 if no audio.
41 int get_output_levels(double *levels
, long position
);
42 int get_module_levels(ArrayList
<double> *module_levels
, long position
);
43 // The MWindow starts the playback cursor loop
44 // The other windows start a slider loop
45 // For pausing only the cursor is run
46 virtual void init_cursor();
47 virtual void stop_cursor();
48 virtual int brender_available(long position
);
49 // For normal playback tracking and the cursor are started
50 virtual void init_tracking();
51 virtual void stop_tracking();
52 // The playback cursor calls this to calculate the current tracking position
53 virtual double get_tracking_position();
54 // Reset the transport after completion
55 virtual void update_transport(int command
, int paused
);
56 // The render engines call this to update tracking variables in the playback engine.
57 void update_tracking(double position
);
61 // Maintain caches through console changes
62 CICache
*audio_cache
, *video_cache
;
63 // Maintain playback cursor on GUI
65 // Tracking variables updated by render engines
66 double tracking_position
;
67 // Not accurate until the first update_tracking, at which time
68 // tracking_active is incremented to 2.
70 // Lock access to tracking data
72 // Block returns until tracking loop is finished
73 Condition
*tracking_done
;
74 // Pause the main loop for the PAUSE command
75 Condition
*pause_lock
;
76 // Wait until thread has started
77 Condition
*start_lock
;
81 // Copy of main preferences
82 Preferences
*preferences
;
85 // Currently executing command
86 TransportCommand
*command
;
87 // Last command which affected transport
92 ArrayList
<RenderEngine
*> render_engines
;
106 int reset_parameters();
108 // ================= position information ======================
109 // get exact position in samples corrected for speed and direction
110 long get_position(int sync_time
= 1);
111 // get total samples rendered since last start with no speed correction
112 // Sync_time uses the video thread to get the current position.
113 // Otherwise a timer or audio device is used.
114 long absolute_position(int sync_time
= 1);
116 // stop and start for user changes
117 int start_reconfigure();
118 int stop_reconfigure();
120 // generic render routine
124 // ============================ cursor
125 int lock_playback_cursor();
126 int unlock_playback_cursor();
127 int lock_playback_movement();
128 int unlock_playback_movement();
129 int move_right(long distance
);
134 // ============================== playback config
135 int infinite
; // for infinite playback
136 int follow_loop
; // 1 if mwindow's looping setting is followed
137 int is_playing_back
; // 0 - no playback 1 - armed but stopped 2 - playing back
138 int reconfigure_status
; // 0 - no playback 1 - armed but stopped 2 - playing back
139 // otherwise use DSP chip if audio tracks are being played
140 int update_button
; // flag for thread on exit
141 int use_buttons
; // flag to update buttons when done or not
142 long last_position
; // starting position for restarting playback
143 long playback_start
, playback_end
; // range for current playback
144 int reverse
; // direction of current playback
145 float speed
; // speed of current playback. A speed of FRAME_SPEED causes frame advance
146 long playback_buffer
;
147 long audio_module_fragment
;
149 // ================================== audio config
150 long input_length
; // number of samples to read from disk at a time
151 // multiple of playback_buffer greater than read_buffer
152 long output_length
; // # of samples to write to device adjusted for speed
153 int shared_audio
; // for duplex audio recording
155 // ================================== video config
157 long correction_factor
; // number of frames to skip to get synchronized
159 RenderEngine
*render_engine
;
164 int init_parameters();
165 int init_audio_device();
166 int init_video_device();
167 Timer timer
; // timer for position information
168 long loop_adjustment
; // for factoring loops into current position