4 * Copyright (C) 1997-2012 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
26 #include "mainsession.h"
28 #include "mwindowgui.h"
31 #include "playbackengine.h"
32 #include "renderengine.h"
33 #include "timelinepane.h"
36 #include "transportque.h"
38 #include "zwindowgui.h"
49 Mixer *Mixers::new_mixer()
52 for( int i=0; i<size(); ++i ) {
53 Mixer *mixer = get(i);
54 if( idx < mixer->idx ) idx = mixer->idx;
56 return append(new Mixer(idx+1));
59 Mixer *Mixers::get_mixer(int idx)
61 for( int i=0; i<size(); ++i ) {
62 Mixer *mixer = get(i);
63 if( mixer->idx == idx ) return mixer;
68 void Mixers::del_mixer(int idx)
70 Mixer *mixer = get_mixer(idx);
71 if( mixer ) remove_object(mixer);
74 void Mixer::set_title(const char *tp)
76 if( tp == title ) return;
77 strncpy(title, !tp ? "" : tp, sizeof(title));
78 title[sizeof(title)-1] = 0;
81 void Mixers::save(FileXML *file)
83 file->tag.set_title("MIXERS");
85 file->append_newline();
86 for( int i=0; i<size(); ++i ) {
87 Mixer *mixer = get(i);
90 file->tag.set_title("/MIXERS");
92 file->append_newline();
95 int Mixers::load(FileXML *file)
98 while( !(result = file->read_tag()) ) {
99 if( file->tag.title_is("/MIXERS") ) break;
100 if( file->tag.title_is("MIXER") ) {
101 Mixer *mixer = new_mixer();
102 file->tag.get_property("TITLE", mixer->title);
103 mixer->x = file->tag.get_property("X", mixer->x);
104 mixer->y = file->tag.get_property("Y", mixer->y);
105 mixer->w = file->tag.get_property("W", mixer->w);
106 mixer->h = file->tag.get_property("H", mixer->h);
113 void Mixers::copy_from(Mixers &that)
115 remove_all_objects();
116 for( int i=0; i<that.size(); ++i ) {
117 Mixer *mixer = new_mixer();
118 mixer->copy_from(*that[i]);
122 void Mixer::save(FileXML *file)
124 file->tag.set_title("MIXER");
125 file->tag.set_property("TITLE",title);
126 file->tag.set_property("X",x);
127 file->tag.set_property("Y",y);
128 file->tag.set_property("W",w);
129 file->tag.set_property("H",h);
131 file->append_newline();
132 for( int i=0; i<mixer_ids.size(); ++i ) {
133 file->tag.set_title("MIX");
134 file->tag.set_property("ID", mixer_ids[i]);
136 file->tag.set_title("/MIX");
138 file->append_newline();
140 file->tag.set_title("/MIXER");
142 file->append_newline();
145 Mixer::Mixer(int idx)
149 x = y = 100 + idx*64;
152 void Mixer::reposition(int x, int y, int w, int h)
154 this->x = x; this->y = y;
155 this->w = w; this->h = h;
158 int Mixer::load(FileXML *file)
161 while( !(result = file->read_tag()) ) {
162 if( file->tag.title_is("/MIXER") ) break;
163 if( file->tag.title_is("MIX") ) {
164 mixer_ids.append(file->tag.get_property("ID", 0));
170 void Mixer::copy_from(Mixer &that)
172 mixer_ids.remove_all();
173 strncpy(title, that.title, sizeof(title));
174 title[sizeof(title)-1] = 0;
175 x = that.x; y = that.y;
176 w = that.w; h = that.h;
177 for( int i=0; i<that.mixer_ids.size(); ++i )
178 mixer_ids.append(that.mixer_ids[i]);
182 ZWindow::ZWindow(MWindow *mwindow)
185 this->mwindow = mwindow;
202 BC_Window* ZWindow::new_gui()
204 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
205 zgui = new ZWindowGUI(mwindow, this, mixer);
206 zgui->create_objects();
210 void ZWindow::handle_done_event(int result)
214 mwindow->del_mixer(this);
217 void ZWindow::handle_close_event(int result)
222 void ZWindow::change_source(EDL *edl)
224 if( this->edl == edl ) return;
225 zgui->playback_engine->refresh_frame(CHANGE_ALL, edl);
227 this->edl->remove_user();
231 void ZWindow::stop_playback(int wait)
233 zgui->playback_engine->stop_playback(wait);
236 void ZWindow::handle_mixer(int command, int wait_tracking,
237 int use_inout, int toggle_audio, int loop_play, float speed)
239 if( !playable ) return;
240 PlaybackEngine *engine = zgui->playback_engine;
241 engine->next_command->toggle_audio = toggle_audio;
242 engine->next_command->loop_play = loop_play;
243 engine->next_command->speed = speed;
244 engine->send_command(command, edl, wait_tracking, use_inout);
247 void ZWindow::update_mixer_ids()
249 if( !running() ) return;
250 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
252 mixer->mixer_ids.remove_all();
253 PatchBay *patchbay = mwindow->gui->pane[0]->patchbay;
254 for( int i=0; i<patchbay->patches.size(); ++i ) {
255 PatchGUI *patchgui = patchbay->patches[i];
256 if( !patchgui->mixer ) continue;
257 int mixer_id = patchgui->track->get_mixer_id();
258 if( mixer->mixer_ids.number_of(mixer_id) >= 0 ) continue;
259 mixer->mixer_ids.append(mixer_id);
263 void ZWindow::set_title(const char *tp)
266 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
268 mixer->set_title(tp);
269 for( track=mwindow->edl->tracks->first; track; track=track->next ) {
270 if( track->data_type != TRACK_VIDEO ) continue;
271 int mixer_id = track->get_mixer_id();
272 int k = mixer->mixer_ids.size();
273 while( --k >= 0 && mixer_id != mixer->mixer_ids[k] );
277 char *cp = title, *ep = cp + sizeof(title)-1;
278 cp += snprintf(title, ep-cp, track ? track->title : _("Mixer %d"), idx);
279 if( tp ) cp += snprintf(cp, ep-cp, ": %s", tp);
283 void ZWindow::reposition(int x, int y, int w, int h)
285 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
287 mixer->reposition(x, y, w, h);