3 #include "edlsession.h"
7 #include "mwindowgui.h"
9 #include "recordlabel.h"
10 #include "mainsession.h"
11 #include "stringfile.h"
18 Labels::Labels(EDL *edl, char *xml_tag)
22 this->xml_tag = xml_tag;
32 for(Label *current = first; current; current = NEXT)
34 printf(" label: %f '%s'\n", current->position, current->textstr);
38 void Labels::insert_labels(Labels *labels, double start, double length, int paste_silence)
44 //printf("Labels::insert_labels 1 %f\n", start);
46 // Insert silence in old labels
49 for(old_label = first; old_label; old_label = old_label->next)
51 if(old_label->position > start ||
52 edl->equivalent(old_label->position, start))
53 old_label->position += length;
58 // Insert one new label at a time
59 for(new_label = labels->first; new_label; new_label = new_label->next)
62 //printf("Labels::insert_labels 2 %f\n", new_label->position + start);
64 // Check every old label for existence
65 for(old_label = first; old_label; old_label = old_label->next)
67 if(edl->equivalent(old_label->position, new_label->position + start))
73 if(old_label->position > new_label->position + start)
80 insert_before(old_label, new Label(edl, this, new_label->position + start, new_label->textstr));
82 append(new Label(edl, this, new_label->position + start, new_label->textstr));
87 int Labels::toggle_label(double start, double end)
90 //printf("Labels::toggle_label 1 %f %f\n", start, end);
92 // handle selection start
93 // find label the selectionstart is after
95 current && current->position < start && !edl->equivalent(current->position, start);
98 //printf("Labels::toggle_label 2 %f %f %f\n", start, end, current->position);
104 //printf("Labels::toggle_label 3 %f %f %f\n", start, end, current->position);
105 if(edl->equivalent(current->position, start))
107 //printf("Labels::toggle_label 1\n");
111 { // insert before it
112 current = insert_before(current, new Label(edl, this, start, ""));
116 { // insert after last
117 //printf("Labels::toggle_label 1\n");
118 current = append(new Label(edl, this, start, ""));
121 // handle selection end
122 if(!EQUIV(start, end))
124 //printf("Labels::toggle_label 2 %.16e %.16e\n", start, end);
125 // find label the selectionend is after
127 current && current->position < end && !edl->equivalent(current->position, end);
135 if(edl->equivalent(current->position, end))
141 current = insert_before(current, new Label(edl, this, end, ""));
146 current = append(new Label(edl, this, end, ""));
152 int Labels::delete_all()
159 int Labels::copy(double start, double end, FileXML *xml)
161 char string[BCTEXTLEN];
162 xml->tag.set_title(xml_tag);
164 xml->append_newline();
167 sprintf(string, xml_tag);
168 string[strlen(string) - 1] = 0;
169 for(current = label_of(start);
170 current && current->position <= end;
173 xml->tag.set_title(string);
174 xml->tag.set_property("TIME", (double)current->position - start);
175 xml->tag.set_property("TEXTSTR", current->textstr);
176 //printf("Labels::copy %f\n", current->position - start);
180 sprintf(string, "/%s", xml_tag);
181 xml->tag.set_title(string);
183 xml->append_newline();
184 xml->append_newline();
188 int Labels::copy_length(long start, long end) // return number of Labels in selection
193 for(current = label_of(start); current && current->position <= end; current = NEXT)
200 void Labels::copy_from(Labels *labels)
202 while(last) delete last;
204 for(Label *current = labels->first; current; current = NEXT)
206 append(new Label(edl, this, current->position, current->textstr));
211 Labels& Labels::operator=(Labels &that)
214 printf("Labels::operator= 1\n");
219 int Labels::save(FileXML *xml)
221 xml->tag.set_title("LABELS");
223 xml->append_newline();
227 for(current = first; current; current = NEXT)
229 xml->tag.set_title("LABEL");
230 xml->tag.set_property("TIME", (double)current->position);
231 xml->tag.set_property("TEXTSTR", current->textstr);
235 xml->append_newline();
236 xml->tag.set_title("/LABELS");
238 xml->append_newline();
239 xml->append_newline();
243 int Labels::load(FileXML *xml, uint32_t load_flags)
246 char string1[BCTEXTLEN], string2[BCTEXTLEN];
248 sprintf(string1, "/%s", xml_tag);
249 strcpy(string2, xml_tag);
250 string2[strlen(string2) - 1] = 0;
253 result = xml->read_tag();
256 if(xml->tag.title_is(string1))
261 if(xml->tag.title_is(string2))
263 double position = xml->tag.get_property("TIME", (double)-1);
265 position = xml->tag.get_property("SAMPLE", (double)-1);
266 //printf("Labels::load %f\n", position);
269 Label *current = label_of(position);
270 current = insert_before(current, new Label(edl, this, position, ""));
271 xml->tag.get_property("TEXTSTR", current->textstr);
275 if(xml->tag.title_is("INPOINT"))
277 double position = xml->tag.get_property("TIME", (double)-1);
279 position = xml->tag.get_property("SAMPLE", (double)-1);
286 if(xml->tag.title_is("OUTPOINT"))
288 double position = xml->tag.get_property("TIME", (double)-1);
290 position = xml->tag.get_property("SAMPLE", (double)-1);
303 int Labels::clear(double start, double end, int follow)
308 //printf("Labels::clear 1\n");
309 current = label_of(start);
310 //printf("Labels::clear 2\n");
311 // remove selected labels
312 while(current && current->position < end)
318 // Shift later labels
319 //printf("Labels::clear 3\n");
324 current->position -= end - start; // shift labels forward
327 //printf("Labels::clear 4\n");
329 //printf("Labels::clear 5\n");
336 Label* Labels::prev_label(double position)
340 // Test for label under cursor position
342 current && !edl->equivalent(current->position, position);
346 // Test for label after cursor position
349 current && current->position < position;
353 // Test for label before cursor position
357 // Get previous label
363 Label* Labels::next_label(double position)
367 // Test for label under cursor position
369 current && !edl->equivalent(current->position, position);
373 // Test for label before cursor position
376 current && current->position > position;
380 // Test for label after cursor position
390 int Labels::insert(double start, double length)
391 { // shift every label including the first one back
394 for(current = label_of(start); current; current = NEXT)
396 current->position += length;
401 int Labels::paste_silence(double start, double end)
403 insert(start, end - start);
408 int Labels::modify_handles(double oldposition,
415 handle_mode == MOVE_ALL_EDITS)
417 if(currentend == 0) // left handle
419 if(newposition < oldposition)
421 insert(oldposition, oldposition - newposition); // shift all labels right
425 clear(oldposition, newposition); // clear selection
430 if(newposition < oldposition)
432 clear(newposition, oldposition);
436 insert(oldposition, newposition - oldposition);
443 int Labels::optimize()
452 for(current = first; current && NEXT && !result;)
455 if(current->position == next->position)
466 Label* Labels::label_of(double position)
470 for(current = first; current; current = NEXT)
472 if(current->position >= position) return current;
491 Label::Label(EDL *edl, Labels *labels, double position, char *textstr = 0)
495 this->labels = labels;
496 this->position = position;
498 strcpy(this->textstr, textstr);
500 strcpy(this->textstr, "");
506 // if(toggle) delete toggle;
509 LabelToggle::LabelToggle(MWindow *mwindow,
516 this->mwindow = mwindow;
520 LabelToggle::~LabelToggle() { }
522 int LabelToggle::handle_event()