rework restore_windows for layout
[goodguy/cinelerra.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         if( tp == title ) return;
76         strncpy(title, !tp ? "" : tp, sizeof(title));
77         title[sizeof(title)-1] = 0;
78 }
79
80 void Mixers::save(FileXML *file)
81 {
82         file->tag.set_title("MIXERS");
83         file->append_tag();
84         file->append_newline();
85         for( int i=0; i<size(); ++i ) {
86                 Mixer *mixer = get(i);
87                 mixer->save(file);
88         }
89         file->tag.set_title("/MIXERS");
90         file->append_tag();
91         file->append_newline();
92 }
93
94 int Mixers::load(FileXML *file)
95 {
96         int result = 0;
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);
106                         mixer->load(file);
107                 }
108         }
109         return 0;
110 }
111
112 void Mixers::copy_from(Mixers &that)
113 {
114         remove_all_objects();
115         for( int i=0; i<that.size(); ++i ) {
116                 Mixer *mixer = new_mixer();
117                 mixer->copy_from(*that[i]);
118         }
119 }
120
121 void Mixer::save(FileXML *file)
122 {
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);
129         file->append_tag();
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]);
134                 file->append_tag();
135                 file->tag.set_title("/MIX");
136                 file->append_tag();
137                 file->append_newline();
138         }
139         file->tag.set_title("/MIXER");
140         file->append_tag();
141         file->append_newline();
142 }
143
144 Mixer::Mixer(int idx)
145 {
146         this->idx = idx;
147         title[0] = 0;
148         x = y = 100 + idx*64;
149         w = 400;  h = 300;
150 }
151 void Mixer::reposition(int x, int y, int w, int h)
152 {
153         this->x = x;  this->y = y;
154         this->w = w;  this->h = h;
155 }
156
157 int Mixer::load(FileXML *file)
158 {
159         int result = 0;
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));
164                 }
165         }
166         return 0;
167 }
168
169 void Mixer::copy_from(Mixer &that)
170 {
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]);
178 }
179
180
181 ZWindow::ZWindow(MWindow *mwindow)
182  : BC_DialogThread()
183 {
184         this->mwindow = mwindow;
185         idx = -1;
186         edl = 0;
187         highlighted = 0;
188         destroy = 1;
189         title[0] = 0;
190         zgui = 0;
191 }
192
193 ZWindow::~ZWindow()
194 {
195         close_window();
196         if( edl )
197                 edl->remove_user();
198 }
199
200 BC_Window* ZWindow::new_gui()
201 {
202         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
203         zgui = new ZWindowGUI(mwindow, this, mixer);
204         zgui->create_objects();
205         return zgui;
206 }
207
208 void ZWindow::handle_done_event(int result)
209 {
210         if( destroy )
211                 mwindow->del_mixer(this);
212         idx = -1;
213 }
214 void ZWindow::handle_close_event(int result)
215 {
216         zgui = 0;
217 }
218
219 void ZWindow::change_source(EDL *edl)
220 {
221         if( this->edl && edl != this->edl )
222                 this->edl->remove_user();
223         this->edl = edl;
224         if( edl != 0 ) {
225                 zgui->playback_engine->refresh_frame(CHANGE_ALL, edl);
226         }
227 }
228
229 void ZWindow::stop_playback(int wait)
230 {
231         zgui->playback_engine->stop_playback(wait);
232 }
233
234 void ZWindow::issue_command(int command, int wait_tracking,
235                 int use_inout, int update_refresh, int toggle_audio, int loop_play)
236 {
237         zgui->playback_engine->issue_command(edl, command,
238                         wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
239 }
240
241 void ZWindow::update_mixer_ids()
242 {
243         if( !running() ) return;
244         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
245         if( !mixer ) return;
246         mixer->mixer_ids.remove_all();
247         PatchBay *patchbay = mwindow->gui->pane[0]->patchbay;
248         for( int i=0; i<patchbay->patches.size(); ++i ) {
249                 PatchGUI *patchgui = patchbay->patches[i];
250                 if( !patchgui->mixer ) continue;
251                 int mixer_id = patchgui->track->get_mixer_id();
252                 if( mixer->mixer_ids.number_of(mixer_id) >= 0 ) continue;
253                 mixer->mixer_ids.append(mixer_id);
254         }
255 }
256
257 void ZWindow::set_title(const char *tp)
258 {
259         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
260         if( mixer ) mixer->set_title(tp);
261         char *cp = title, *ep = cp + sizeof(title)-1;
262         cp += snprintf(title, ep-cp, _("Mixer %d"), idx);
263         if( tp ) cp += snprintf(cp, ep-cp, ": %s", tp);
264         *cp = 0;
265 }
266
267 void ZWindow::reposition(int x, int y, int w, int h)
268 {
269         Mixer *mixer = mwindow->edl->mixers.get_mixer(idx);
270         if( !mixer ) return;
271         mixer->reposition(x, y, w, h);
272 }
273