identity sh-f11=cam/sh-f12=proj keyframes, odd jpeg fix, zoom submenu, shudmp
[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  *
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 "awindow.h"
23 #include "awindowgui.h"
24 #include "bcsignals.h"
25 #include "clipedit.h"
26 #include "edl.h"
27 #include "fonts.h"
28 #include "language.h"
29 #include "localsession.h"
30 #include "mainerror.h"
31 #include "mainsession.h"
32 #include "mwindow.h"
33 #include "mwindowgui.h"
34 #include "vwindow.h"
35 #include "vwindowgui.h"
36 #include "errorbox.h"
37 #include "tracks.h"
38
39
40
41 ClipEdit::ClipEdit(MWindow *mwindow, AWindow *awindow, VWindow *vwindow)
42  : BC_DialogThread()
43 {
44         this->mwindow = mwindow;
45         this->awindow = awindow;
46         this->vwindow = vwindow;
47         this->clip = 0;
48         this->create_it = 0;
49 }
50
51 ClipEdit::~ClipEdit()
52 {
53         close_window();
54 }
55
56 // After the window is closed and deleted, this is called.
57 void ClipEdit::handle_close_event(int result)
58 {
59         if( !result ) {
60                 int name_ok = 1;
61                 for( int i=0; name_ok && i<mwindow->edl->clips.size(); ++i ) {
62                         if( !strcasecmp(clip->local_session->clip_title,
63                               mwindow->edl->clips[i]->local_session->clip_title) &&
64                             (create_it || strcasecmp(clip->local_session->clip_title,
65                                original->local_session->clip_title)) )
66                                 name_ok = 0;
67                 }
68                 if( !name_ok ) {
69                         eprintf(_("A clip with that name already exists."));
70                         result = 1;
71                 }
72         }
73
74         if( !result ) {
75 // Add to EDL
76                 if( create_it )
77                         mwindow->edl->add_clip(clip);
78                 else // Copy clip to existing clip in EDL
79                         original->copy_session(clip);
80 //              mwindow->vwindow->gui->update_sources(mwindow->vwindow->gui->source->get_text());
81                 mwindow->awindow->gui->async_update_assets();
82
83 // Change VWindow to it if vwindow was called
84 // But this doesn't let you easily create a lot of clips.
85                 if( vwindow && create_it ) {
86 //                              vwindow->change_source(new_edl);
87                 }
88                 mwindow->session->update_clip_number();
89         }
90
91 // always a copy from new_gui
92         clip->remove_user();
93         original = 0;
94         clip = 0;
95         create_it = 0;
96 }
97
98
99 // User creates the window and initializes it here.
100 BC_Window* ClipEdit::new_gui()
101 {
102         original = clip;
103         this->clip = new EDL(mwindow->edl);
104         clip->create_objects();
105         clip->copy_all(original);
106
107         window = new ClipEditWindow(mwindow, this);
108         window->create_objects();
109         return window;
110 }
111
112
113
114 void ClipEdit::edit_clip(EDL *clip, int x, int y)
115 {
116         close_window();
117
118         this->clip = clip;
119         this->create_it = 0;
120         this->x = x;  this->y = y;
121         start();
122 }
123
124 void ClipEdit::create_clip(EDL *clip, int x, int y)
125 {
126         close_window();
127
128         this->clip = clip;
129         this->create_it = 1;
130         this->x = x;  this->y = y;
131         start();
132 }
133
134
135 ClipEditWindow::ClipEditWindow(MWindow *mwindow, ClipEdit *thread)
136  : BC_Window(_(PROGRAM_NAME ": Clip Info"),
137         thread->x -400/2, thread->y - 350/2,
138         400, 350, 400, 430, 0, 0, 1)
139 {
140         this->mwindow = mwindow;
141         this->thread = thread;
142 }
143
144 ClipEditWindow::~ClipEditWindow()
145 {
146 }
147
148
149 void ClipEditWindow::create_objects()
150 {
151         lock_window("ClipEditWindow::create_objects");
152         this->create_it = thread->create_it;
153
154         int x = 10, y = 10;
155         int x1 = x;
156         BC_TextBox *textbox;
157         BC_Title *title;
158
159         add_subwindow(title = new BC_Title(x1, y, _("Title:")));
160         y += title->get_h() + 5;
161         add_subwindow(titlebox = new ClipEditTitle(this, x1, y, get_w() - x1 * 2));
162
163         int end = strlen(titlebox->get_text());
164         titlebox->set_selection(0, end, end);
165
166         y += titlebox->get_h() + 10;
167         add_subwindow(title = new BC_Title(x1, y, _("Comments:")));
168         y += title->get_h() + 5;
169         add_subwindow(textbox = new ClipEditComments(this,
170                 x1,
171                 y,
172                 get_w() - x1 * 2,
173                 BC_TextBox::pixels_to_rows(this,
174                         MEDIUMFONT,
175                         get_h() - 10 - BC_OKButton::calculate_h() - y)));
176
177
178
179         add_subwindow(new BC_OKButton(this));
180         add_subwindow(new BC_CancelButton(this));
181         show_window();
182         titlebox->activate();
183         unlock_window();
184 }
185
186
187
188
189
190 ClipEditTitle::ClipEditTitle(ClipEditWindow *window, int x, int y, int w)
191  : BC_TextBox(x, y, w, 1, window->thread->clip->local_session->clip_title)
192 {
193         this->window = window;
194 }
195
196 int ClipEditTitle::handle_event()
197 {
198         strcpy(window->thread->clip->local_session->clip_title, get_text());
199         return 1;
200 }
201
202
203
204
205
206 ClipEditComments::ClipEditComments(ClipEditWindow *window, int x, int y, int w, int rows)
207  : BC_TextBox(x, y, w, rows, window->thread->clip->local_session->clip_notes)
208 {
209         this->window = window;
210 }
211
212 int ClipEditComments::handle_event()
213 {
214         strcpy(window->thread->clip->local_session->clip_notes, get_text());
215         return 1;
216 }