Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / clipedit.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  * Copyright (C) 2003-2016 Cinelerra CV contributors
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #include "awindow.h"
24 #include "awindowgui.h"
25 #include "bcsignals.h"
26 #include "clipedit.h"
27 #include "edl.h"
28 #include "fonts.h"
29 #include "language.h"
30 #include "localsession.h"
31 #include "mainerror.h"
32 #include "mainsession.h"
33 #include "mwindow.h"
34 #include "mwindowgui.h"
35 #include "vwindow.h"
36 #include "vwindowgui.h"
37 #include "errorbox.h"
38 #include "tracks.h"
39
40
41
42 ClipEdit::ClipEdit(MWindow *mwindow, AWindow *awindow, VWindow *vwindow)
43  : BC_DialogThread()
44 {
45         this->mwindow = mwindow;
46         this->awindow = awindow;
47         this->vwindow = vwindow;
48         this->clip = 0;
49         this->create_it = 0;
50 }
51
52 ClipEdit::~ClipEdit()
53 {
54         close_window();
55 }
56
57 // After the window is closed and deleted, this is called.
58 void ClipEdit::handle_close_event(int result)
59 {
60         if( !result ) {
61                 int name_ok = 1;
62                 for( int i=0; name_ok && i<mwindow->edl->clips.size(); ++i ) {
63                         if( !strcasecmp(clip->local_session->clip_title,
64                               mwindow->edl->clips[i]->local_session->clip_title) &&
65                             (create_it || strcasecmp(clip->local_session->clip_title,
66                                original->local_session->clip_title)) )
67                                 name_ok = 0;
68                 }
69                 if( !name_ok ) {
70                         eprintf(_("A clip with that name already exists."));
71                         result = 1;
72                 }
73         }
74
75         if( !result ) {
76 // Add to EDL
77                 if( create_it )
78                         mwindow->edl->add_clip(clip);
79                 else // Copy clip to existing clip in EDL
80                         original->copy_session(clip);
81 //              mwindow->vwindow->gui->update_sources(mwindow->vwindow->gui->source->get_text());
82                 mwindow->awindow->gui->async_update_assets();
83
84 // Change VWindow to it if vwindow was called
85 // But this doesn't let you easily create a lot of clips.
86                 if( vwindow && create_it ) {
87 //                              vwindow->change_source(new_edl);
88                 }
89                 mwindow->session->update_clip_number();
90         }
91
92 // always a copy from new_gui
93         clip->remove_user();
94         original = 0;
95         clip = 0;
96         create_it = 0;
97 }
98
99
100 // User creates the window and initializes it here.
101 BC_Window* ClipEdit::new_gui()
102 {
103         original = clip;
104         this->clip = new EDL(mwindow->edl);
105         clip->create_objects();
106         clip->copy_all(original);
107
108         window = new ClipEditWindow(mwindow, this);
109         window->create_objects();
110         return window;
111 }
112
113
114
115 void ClipEdit::edit_clip(EDL *clip, int x, int y)
116 {
117         close_window();
118
119         this->clip = clip;
120         this->create_it = 0;
121         this->x = x;  this->y = y;
122         start();
123 }
124
125 void ClipEdit::create_clip(EDL *clip, int x, int y)
126 {
127         close_window();
128
129         this->clip = clip;
130         this->create_it = 1;
131         this->x = x;  this->y = y;
132         start();
133 }
134
135 #define CEW_W xS(400)
136 #define CEW_H yS(350)
137
138 ClipEditWindow::ClipEditWindow(MWindow *mwindow, ClipEdit *thread)
139  : BC_Window(_(PROGRAM_NAME ": Clip Info"),
140         thread->x - CEW_W/2, thread->y - CEW_H/2,
141         CEW_W, CEW_H, CEW_W, CEW_H, 0, 0, 1)
142 {
143         this->mwindow = mwindow;
144         this->thread = thread;
145 // *** CONTEXT_HELP ***
146         context_help_set_keyword("Workflow with OpenEDL and Nested Clips");
147 }
148
149 ClipEditWindow::~ClipEditWindow()
150 {
151 }
152
153
154 void ClipEditWindow::create_objects()
155 {
156         int xs10 = xS(10);
157         int ys5 = yS(5), ys10 = yS(10);
158         lock_window("ClipEditWindow::create_objects");
159         this->create_it = thread->create_it;
160
161         int x = xs10, y = ys10;
162         int x1 = x;
163         BC_TextBox *textbox;
164         BC_Title *title;
165
166         add_subwindow(title = new BC_Title(x1, y, _("Title:")));
167         y += title->get_h() + ys5;
168         add_subwindow(titlebox = new ClipEditTitle(this, x1, y, get_w() - x1 * 2));
169
170         int end = strlen(titlebox->get_text());
171         titlebox->set_selection(0, end, end);
172
173         y += titlebox->get_h() + ys10;
174         add_subwindow(title = new BC_Title(x1, y, _("Comments:")));
175         y += title->get_h() + ys5;
176         add_subwindow(textbox = new ClipEditComments(this,
177                 x1,
178                 y,
179                 get_w() - x1 * 2,
180                 BC_TextBox::pixels_to_rows(this,
181                         MEDIUMFONT,
182                         get_h() - ys10 - BC_OKButton::calculate_h() - y)));
183
184
185
186         add_subwindow(new BC_OKButton(this));
187         add_subwindow(new BC_CancelButton(this));
188         show_window();
189         titlebox->activate();
190         unlock_window();
191 }
192
193
194
195
196
197 ClipEditTitle::ClipEditTitle(ClipEditWindow *window, int x, int y, int w)
198  : BC_TextBox(x, y, w, 1, window->thread->clip->local_session->clip_title)
199 {
200         this->window = window;
201 }
202
203 int ClipEditTitle::handle_event()
204 {
205         strcpy(window->thread->clip->local_session->clip_title, get_text());
206         return 1;
207 }
208
209
210
211
212
213 ClipEditComments::ClipEditComments(ClipEditWindow *window, int x, int y, int w, int rows)
214  : BC_TextBox(x, y, w, rows, window->thread->clip->local_session->clip_notes)
215 {
216         this->window = window;
217 }
218
219 int ClipEditComments::handle_event()
220 {
221         strcpy(window->thread->clip->local_session->clip_notes, get_text());
222         return 1;
223 }