update internationalization data
[goodguy/history.git] / cinelerra-5.0 / cinelerra / editlength.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2009 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 "bcdisplayinfo.h"
23 #include "clip.h"
24 #include "edit.h"
25 #include "editlength.h"
26 #include "edits.h"
27 #include "edl.h"
28 #include "edlsession.h"
29 #include "language.h"
30 #include "localsession.h"
31 #include "mwindow.h"
32 #include "mwindowgui.h"
33 #include "track.h"
34 #include "tracks.h"
35
36
37 EditLengthThread::EditLengthThread(MWindow *mwindow)
38  : BC_DialogThread()
39 {
40         this->mwindow = mwindow;
41 }
42
43 EditLengthThread::~EditLengthThread()
44 {
45 }
46
47 void EditLengthThread::start(Edit *edit)
48 {
49         this->edit = edit;
50
51         orig_length = 0;
52         length = 0;
53
54         double start = mwindow->edl->local_session->get_selectionstart();
55         double end = mwindow->edl->local_session->get_selectionend();
56
57 // get the default length from the first edit selected  
58         if(!edit)
59         {
60                 Track *track = 0;
61                 int got_it = 0;
62                 for(track = mwindow->edl->tracks->first;
63                         track && !got_it;
64                         track = track->next)
65                 {
66                         if(track->record)
67                         {
68                                 int64_t start_units = track->to_units(start, 0);
69                                 int64_t end_units = track->to_units(end, 0);
70
71                                 for(edit = track->edits->first;
72                                         edit && !got_it;
73                                         edit = edit->next)
74                                 {
75                                         if(edit->startproject >= start_units &&
76                                                 edit->startproject < end_units)
77                                         {
78                                                 this->length = 
79                                                         this->orig_length = 
80                                                         track->from_units(edit->length);
81                                                 got_it = 1;
82                                         }
83                                 }
84                         }
85                 }
86         }
87
88         BC_DialogThread::start();
89 }
90
91 BC_Window* EditLengthThread::new_gui()
92 {
93         BC_DisplayInfo display_info;
94         int x = display_info.get_abs_cursor_x() - 150;
95         int y = display_info.get_abs_cursor_y() - 50;
96         EditLengthDialog *gui = new EditLengthDialog(mwindow, 
97                 this,
98                 x,
99                 y);
100         gui->create_objects();
101         return gui;
102 }
103
104 void EditLengthThread::handle_close_event(int result)
105 {
106         if(!result)
107         {
108                 if(edit)
109                 {
110 //                      mwindow->set_edit_length(edit, length);
111                 }
112                 else
113                 {
114                         mwindow->set_edit_length(length);
115                 }
116         }
117 }
118
119
120
121
122
123
124
125
126
127 EditLengthDialog::EditLengthDialog(MWindow *mwindow, 
128         EditLengthThread *thread,
129         int x,
130         int y)
131  : BC_Window(_(PROGRAM_NAME ": Edit length"), 
132         x,
133         y,
134         300, 
135         100, 
136         -1, 
137         -1, 
138         0,
139         0, 
140         1)
141 {
142         this->mwindow = mwindow;
143         this->thread = thread;
144 }
145
146 EditLengthDialog::~EditLengthDialog()
147 {
148 }
149
150         
151 void EditLengthDialog::create_objects()
152 {
153         lock_window("EditLengthDialog::create_objects");
154         add_subwindow(new BC_Title(10, 10, _("Seconds:")));
155         text = new EditLengthText(mwindow, this, 100, 10);
156         text->create_objects();
157         add_subwindow(new BC_OKButton(this));
158         add_subwindow(new BC_CancelButton(this));
159         show_window();
160         unlock_window();
161 }
162
163 int EditLengthDialog::close_event()
164 {
165         set_done(0);
166         return 1;
167 }
168
169
170
171
172
173
174 EditLengthText::EditLengthText(MWindow *mwindow, 
175         EditLengthDialog *gui,
176         int x, 
177         int y)
178  : BC_TumbleTextBox(gui, 
179         (float)gui->thread->length,
180         (float)0, 
181         (float)100, 
182         x,
183         y,
184         100)
185 {
186         this->mwindow = mwindow;
187         this->gui = gui;
188 }
189
190 int EditLengthText::handle_event()
191 {
192         double result = atof(get_text());
193         if(fabs(result - gui->thread->length) > 0.000001)
194         {
195                 gui->thread->length = result;
196         }
197
198         return 1;
199 }
200
201
202
203
204
205
206
207
208
209