mixer
[goodguy/history.git] / cinelerra-5.1 / cinelerra / zwindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2012 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdialog.h"
23 #include "edl.h"
24 #include "filexml.h"
25 #include "language.h"
26 #include "mainsession.h"
27 #include "mwindow.h"
28 #include "mwindowgui.h"
29 #include "patchbay.h"
30 #include "patchgui.h"
31 #include "playbackengine.h"
32 #include "renderengine.h"
33 #include "timelinepane.h"
34 #include "track.h"
35 #include "transportque.h"
36 #include "zwindow.h"
37 #include "zwindowgui.h"
38
39 Mixers::Mixers()
40 {
41 }
42
43 Mixers::~Mixers()
44 {
45         remove_all_objects();
46 }
47
48 Mixer *Mixers::new_mixer()
49 {
50         int idx = 0;
51         for( int i=0; i<size(); ++i ) {
52                 Mixer *mixer = get(i);
53                 if( idx < mixer->idx ) idx = mixer->idx;
54         }
55         return append(new Mixer(idx+1));
56 }
57
58 Mixer *Mixers::get_mixer(int idx)
59 {
60         for( int i=0; i<size(); ++i ) {
61                 Mixer *mixer = get(i);
62                 if( mixer->idx == idx ) return mixer;
63         }
64         return 0;
65 }
66
67 void Mixers::del_mixer(int idx)
68 {
69         Mixer *mixer = get_mixer(idx);
70         if( mixer ) remove_object(mixer);
71 }
72
73 void Mixer::set_title(const char *tp)
74 {
75         strncpy(title, tp, sizeof(title));
76         title[sizeof(title)-1] = 0;
77 }
78
79 void Mixers::save(FileXML *file)
80 {
81         file->tag.set_title("MIXERS");
82         file->append_tag();
83         file->append_newline();
84         for( int i=0; i<size(); ++i ) {
85                 Mixer *mixer = get(i);
86                 mixer->save(file);
87         }
88         file->tag.set_title("/MIXERS");
89         file->append_tag();
90         file->append_newline();
91 }
92
93 int Mixers::load(FileXML *file)
94 {
95         int result = 0;
96         while( !(result = file->read_tag()) ) {
97                 if( file->tag.title_is("/MIXERS") ) break;
98                 if( file->tag.title_is("MIXER") ) {
99                         Mixer *mixer = new_mixer();
100                         file->tag.get_property("TITLE", mixer->title);
101                         mixer->x = file->tag.get_property("X", mixer->x);
102                         mixer->y = file->tag.get_property("Y", mixer->y);
103                         mixer->w = file->tag.get_property("W", mixer->w);
104                         mixer->h = file->tag.get_property("H", mixer->h);
105                         mixer->load(file);
106                 }
107         }
108         return 0;
109 }
110
111 void Mixers::copy_from(Mixers &that)
112 {
113         remove_all_objects();
114         for( int i=0; i<that.size(); ++i ) {
115                 Mixer *mixer = new_mixer();
116                 mixer->copy_from(*that[i]);
117         }
118 }
119
120 void Mixer::save(FileXML *file)
121 {
122         file->tag.set_title("MIXER");
123         file->tag.set_property("TITLE",title);
124         file->tag.set_property("X",x);
125         file->tag.set_property("Y",y);
126         file->tag.set_property("W",w);
127         file->tag.set_property("H",h);
128         file->append_tag();
129         file->append_newline();
130         for( int i=0; i<mixer_ids.size(); ++i ) {
131                 file->tag.set_title("MIX");
132                 file->tag.set_property("ID", mixer_ids[i]);
133                 file->append_tag();
134                 file->tag.set_title("/MIX");
135                 file->append_tag();
136                 file->append_newline();
137         }
138         file->tag.set_title("/MIXER");
139         file->append_tag();
140         file->append_newline();
141 }
142
143 Mixer::Mixer(int idx)
144 {
145         this->idx = idx;
146         title[0] = 0;
147         x = y = 100 + idx*64;
148         w = 400;  h = 300;
149 }
150 void Mixer::reposition(int x, int y, int w, int h)
151 {
152         this->x = x;  this->y = y;
153         this->w = w;  this->h = h;
154 }
155
156 int Mixer::load(FileXML *file)
157 {
158         int result = 0;
159         while( !(result = file->read_tag()) ) {
160                 if( file->tag.title_is("/MIXER") ) break;
161                 if( file->tag.title_is("MIX") ) {
162                         mixer_ids.append(file->tag.get_property("ID", 0));
163                 }
164         }
165         return 0;
166 }
167
168 void Mixer::copy_from(Mixer &that)
169 {
170         mixer_ids.remove_all();
171         strncpy(title, that.title, sizeof(title));
172         title[sizeof(title)-1] = 0;
173         x = that.x;  y = that.y;
174         w = that.w;  h = that.h;
175         for( int i=0; i<that.mixer_ids.size(); ++i )
176                 mixer_ids.append(that.mixer_ids[i]);
177 }
178
179
180 ZWindow::ZWindow(MWindow *mwindow)
181  : BC_DialogThread()
182 {
183         this->mwindow = mwindow;
184         idx = -1;
185         edl = 0;
186         highlighted = 0;
187         title[0] = 0;
188         zgui = 0;
189 }
190
191 ZWindow::~ZWindow()
192 {
193         close_window();
194         if( edl )
195                 edl->remove_user();
196 }
197
198 BC_Window* ZWindow::new_gui()
199 {
200         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
201         zgui = new ZWindowGUI(mwindow, this, mixer);
202         zgui->create_objects();
203         return zgui;
204 }
205
206 void ZWindow::handle_done_event(int result)
207 {
208 }
209 void ZWindow::handle_close_event(int result)
210 {
211         zgui = 0;
212 }
213
214 void ZWindow::change_source(EDL *edl)
215 {
216         if( this->edl && edl != this->edl )
217                 this->edl->remove_user();
218         this->edl = edl;
219         if( edl != 0 ) {
220                 zgui->playback_engine->que->send_command(CURRENT_FRAME, CHANGE_ALL, edl, 1);
221         }
222 }
223
224 void ZWindow::issue_command(int command, int wait_tracking,
225                 int use_inout, int update_refresh, int toggle_audio)
226 {
227         zgui->playback_engine->issue_command(edl, command,
228                         wait_tracking, use_inout, update_refresh, toggle_audio);
229 }
230
231 void ZWindow::update_mixer_ids()
232 {
233         if( !running() ) return;
234         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
235         if( !mixer ) return;
236         mixer->mixer_ids.remove_all();
237         PatchBay *patchbay = mwindow->gui->pane[0]->patchbay;
238         for( int i=0; i<patchbay->patches.size(); ++i ) {
239                 PatchGUI *patchgui = patchbay->patches[i];
240                 if( !patchgui->mixer ) continue;
241                 int mixer_id = patchgui->track->get_mixer_id();
242                 if( mixer->mixer_ids.number_of(mixer_id) >= 0 ) continue;
243                 mixer->mixer_ids.append(mixer_id);
244         }
245 }
246
247 void ZWindow::set_title(const char *tp)
248 {
249         char *cp = title, *ep = cp + sizeof(title)-1;
250         cp += snprintf(title, ep-cp, _("Mixer %d"), idx);
251         if( tp ) cp += snprintf(cp, ep-cp, ": %s", tp);
252         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
253         if( mixer && tp != mixer->title ) mixer->set_title(tp);
254 }
255
256 void ZWindow::reposition(int x, int y, int w, int h)
257 {
258         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
259         if( mixer ) mixer->reposition(x, y, w, h);
260 }
261