r1006: configure: Use libx264_pic instead of libx264 if available.
[cinelerra_cv/mob.git] / cinelerra / clipedit.C
blob46f6a4781511d45ccbae01f67b4e7b5c4a2102a2
1 #include "awindow.h"
2 #include "awindowgui.h"
3 #include "clipedit.h"
4 #include "edl.h"
5 #include "fonts.h"
6 #include "language.h"
7 #include "localsession.h"
8 #include "mainsession.h"
9 #include "mwindow.h"
10 #include "mwindowgui.h"
11 #include "vwindow.h"
12 #include "vwindowgui.h"
13 #include "errorbox.h"
14 #include "tracks.h"
18 ClipEdit::ClipEdit(MWindow *mwindow, AWindow *awindow, VWindow *vwindow)
19  : Thread()
21         this->mwindow = mwindow;
22         this->awindow = awindow;
23         this->vwindow = vwindow;
24         this->clip = 0;
25         this->create_it = 0;
28 ClipEdit::~ClipEdit()
32 void ClipEdit::edit_clip(EDL *clip)
34 // Allow more than one window so we don't have to delete the clip in handle_event
35         if(clip)
36         {
37                 this->clip = clip;
38                 this->create_it = 0;
39                 Thread::start();
40         }
43 void ClipEdit::create_clip(EDL *clip)
45 // Allow more than one window so we don't have to delete the clip in handle_event
46         if(clip)
47         {
48                 this->clip = clip;
49                 this->create_it = 1;
50                 Thread::start();
51         }
54 void ClipEdit::run()
56         if(clip)
57         {
58                 EDL *original = clip;
59                 if(!create_it)
60                 {
61                         clip = new EDL(mwindow->edl);
62                         clip->create_objects();
63                         clip->copy_all(original);
64                 }
73                 ClipEditWindow *window = new ClipEditWindow(mwindow, this);
75                 window->create_objects();
77                 int  name_ok_or_cancel = 0;
78                 int result;
79                 while (!name_ok_or_cancel)
80                 { 
81                         result = window->run_window();
82                         if (result)
83                                 name_ok_or_cancel = 1;
84                         else
85                         {
86                                 // Check if clip name is unique
87                                 name_ok_or_cancel = 1;
88                                 for (int i = 0; i < mwindow->edl->clips.total; i++)
89                                 {
90                                         if (!strcasecmp(clip->local_session->clip_title,
91                                                 mwindow->edl->clips.values[i]->local_session->clip_title) &&
92                                                 (create_it || strcasecmp(clip->local_session->clip_title,
93                                                 original->local_session->clip_title)))
94                                         
95                                                 name_ok_or_cancel = 0;
96                                 }
97                                 if (!name_ok_or_cancel)
98                                 {
99                                         ErrorBox error(PROGRAM_NAME ": Error", 
100                                                 mwindow->gui->get_abs_cursor_x(1), 
101                                                 mwindow->gui->get_abs_cursor_y(1));
102                                         error.create_objects(_("A clip with that name already exists."));
103                                         error.run_window();
104                                         window->titlebox->activate();
105                                 }
106                         }
107                 }
109                 if(!result)
110                 {
111                         EDL *new_edl = 0;
112 // Add to EDL
113                         if(create_it)
114                                 new_edl = mwindow->edl->add_clip(window->clip);
116 // Copy clip to existing clip in EDL
117                         if(!create_it)
118                                 original->copy_session(clip);
121 //                      mwindow->vwindow->gui->update_sources(mwindow->vwindow->gui->source->get_text());
124                         mwindow->awindow->gui->async_update_assets();
126 // Change VWindow to it if vwindow was called
127 // But this doesn't let you easily create a lot of clips.
128                         if(vwindow && create_it)
129                         {
130 //                              vwindow->change_source(new_edl);
131                         }
132                 }
133                 else
134                 {
135                         mwindow->session->clip_number--;
136                 }
137                 
140 // For creating new clips, the original was copied in add_clip.
141 // For editing old clips, the original was transferred to another variable.
142                 delete window->clip;
143                 delete window;
144                 clip = 0;
145                 create_it = 0;
146         }
155 ClipEditWindow::ClipEditWindow(MWindow *mwindow, ClipEdit *thread)
156  : BC_Window(PROGRAM_NAME ": Clip Info", 
157         mwindow->gui->get_abs_cursor_x(1) - 400 / 2,
158         mwindow->gui->get_abs_cursor_y(1) - 350 / 2,
159         400, 
160         350,
161         400,
162         430,
163         0,
164         0,
165         1)
167         this->mwindow = mwindow;
168         this->thread = thread;
171 ClipEditWindow::~ClipEditWindow()
175         
176 void ClipEditWindow::create_objects()
178         this->clip = thread->clip;
179         this->create_it = thread->create_it;
181         int x = 10, y = 10;
182         int x1 = x;
183         BC_TextBox *textbox;
184         BC_Title *title;
186         add_subwindow(title = new BC_Title(x1, y, _("Title:")));
187         y += title->get_h() + 5;
188         add_subwindow(titlebox = new ClipEditTitle(this, x1, y, get_w() - x1 * 2));
189         y += titlebox->get_h() + 10;
190         add_subwindow(title = new BC_Title(x1, y, _("Comments:")));
191         y += title->get_h() + 5;
192         add_subwindow(textbox = new ClipEditComments(this, 
193                 x1, 
194                 y, 
195                 get_w() - x1 * 2, 
196                 BC_TextBox::pixels_to_rows(this, 
197                         MEDIUMFONT, 
198                         get_h() - 10 - BC_OKButton::calculate_h() - y)));
202         add_subwindow(new BC_OKButton(this));
203         add_subwindow(new BC_CancelButton(this));
204         show_window();
205         titlebox->activate();
212 ClipEditTitle::ClipEditTitle(ClipEditWindow *window, int x, int y, int w)
213  : BC_TextBox(x, y, w, 1, window->clip->local_session->clip_title)
215         this->window = window;
218 int ClipEditTitle::handle_event()
220         strcpy(window->clip->local_session->clip_title, get_text());
221         return 1;
228 ClipEditComments::ClipEditComments(ClipEditWindow *window, int x, int y, int w, int rows)
229  : BC_TextBox(x, y, w, rows, window->clip->local_session->clip_notes)
231         this->window = window;
234 int ClipEditComments::handle_event()
236         strcpy(window->clip->local_session->clip_notes, get_text());
237         return 1;