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"
35 #include "transportque.h"
37 #include "zwindowgui.h"
48 Mixer *Mixers::new_mixer()
51 for( int i=0; i<size(); ++i ) {
52 Mixer *mixer = get(i);
53 if( idx < mixer->idx ) idx = mixer->idx;
55 return append(new Mixer(idx+1));
58 Mixer *Mixers::get_mixer(int idx)
60 for( int i=0; i<size(); ++i ) {
61 Mixer *mixer = get(i);
62 if( mixer->idx == idx ) return mixer;
67 void Mixers::del_mixer(int idx)
69 Mixer *mixer = get_mixer(idx);
70 if( mixer ) remove_object(mixer);
73 void Mixer::set_title(const char *tp)
75 if( tp == title ) return;
76 strncpy(title, !tp ? "" : tp, sizeof(title));
77 title[sizeof(title)-1] = 0;
80 void Mixers::save(FileXML *file)
82 file->tag.set_title("MIXERS");
84 file->append_newline();
85 for( int i=0; i<size(); ++i ) {
86 Mixer *mixer = get(i);
89 file->tag.set_title("/MIXERS");
91 file->append_newline();
94 int Mixers::load(FileXML *file)
97 while( !(result = file->read_tag()) ) {
98 if( file->tag.title_is("/MIXERS") ) break;
99 if( file->tag.title_is("MIXER") ) {
100 Mixer *mixer = new_mixer();
101 file->tag.get_property("TITLE", mixer->title);
102 mixer->x = file->tag.get_property("X", mixer->x);
103 mixer->y = file->tag.get_property("Y", mixer->y);
104 mixer->w = file->tag.get_property("W", mixer->w);
105 mixer->h = file->tag.get_property("H", mixer->h);
112 void Mixers::copy_from(Mixers &that)
114 remove_all_objects();
115 for( int i=0; i<that.size(); ++i ) {
116 Mixer *mixer = new_mixer();
117 mixer->copy_from(*that[i]);
121 void Mixer::save(FileXML *file)
123 file->tag.set_title("MIXER");
124 file->tag.set_property("TITLE",title);
125 file->tag.set_property("X",x);
126 file->tag.set_property("Y",y);
127 file->tag.set_property("W",w);
128 file->tag.set_property("H",h);
130 file->append_newline();
131 for( int i=0; i<mixer_ids.size(); ++i ) {
132 file->tag.set_title("MIX");
133 file->tag.set_property("ID", mixer_ids[i]);
135 file->tag.set_title("/MIX");
137 file->append_newline();
139 file->tag.set_title("/MIXER");
141 file->append_newline();
144 Mixer::Mixer(int idx)
148 x = y = 100 + idx*64;
151 void Mixer::reposition(int x, int y, int w, int h)
153 this->x = x; this->y = y;
154 this->w = w; this->h = h;
157 int Mixer::load(FileXML *file)
160 while( !(result = file->read_tag()) ) {
161 if( file->tag.title_is("/MIXER") ) break;
162 if( file->tag.title_is("MIX") ) {
163 mixer_ids.append(file->tag.get_property("ID", 0));
169 void Mixer::copy_from(Mixer &that)
171 mixer_ids.remove_all();
172 strncpy(title, that.title, sizeof(title));
173 title[sizeof(title)-1] = 0;
174 x = that.x; y = that.y;
175 w = that.w; h = that.h;
176 for( int i=0; i<that.mixer_ids.size(); ++i )
177 mixer_ids.append(that.mixer_ids[i]);
181 ZWindow::ZWindow(MWindow *mwindow)
184 this->mwindow = mwindow;
200 BC_Window* ZWindow::new_gui()
202 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
203 zgui = new ZWindowGUI(mwindow, this, mixer);
204 zgui->create_objects();
208 void ZWindow::handle_done_event(int result)
211 mwindow->del_mixer(this);
214 void ZWindow::handle_close_event(int result)
219 void ZWindow::change_source(EDL *edl)
221 if( this->edl && edl != this->edl )
222 this->edl->remove_user();
225 zgui->playback_engine->refresh_frame(CHANGE_ALL, edl);
229 void ZWindow::stop_playback(int wait)
231 zgui->playback_engine->stop_playback(wait);
234 void ZWindow::handle_mixer(int command, int wait_tracking,
235 int use_inout, int toggle_audio, int loop_play, float speed)
237 PlaybackEngine *engine = zgui->playback_engine;
238 engine->next_command->toggle_audio = toggle_audio;
239 engine->next_command->loop_play = loop_play;
240 engine->next_command->speed = speed;
241 engine->send_command(command, edl, wait_tracking, use_inout);
244 void ZWindow::update_mixer_ids()
246 if( !running() ) return;
247 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
249 mixer->mixer_ids.remove_all();
250 PatchBay *patchbay = mwindow->gui->pane[0]->patchbay;
251 for( int i=0; i<patchbay->patches.size(); ++i ) {
252 PatchGUI *patchgui = patchbay->patches[i];
253 if( !patchgui->mixer ) continue;
254 int mixer_id = patchgui->track->get_mixer_id();
255 if( mixer->mixer_ids.number_of(mixer_id) >= 0 ) continue;
256 mixer->mixer_ids.append(mixer_id);
260 void ZWindow::set_title(const char *tp)
262 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
263 if( mixer ) mixer->set_title(tp);
264 char *cp = title, *ep = cp + sizeof(title)-1;
265 cp += snprintf(title, ep-cp, _("Mixer %d"), idx);
266 if( tp ) cp += snprintf(cp, ep-cp, ": %s", tp);
270 void ZWindow::reposition(int x, int y, int w, int h)
272 Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
274 mixer->reposition(x, y, w, h);