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\n", current->position);
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));
82 append(new Label(edl, this, new_label->position + start));
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("SAMPLE", (double)current->position - start);
175 //printf("Labels::copy %f\n", current->position - start);
179 sprintf(string, "/%s", xml_tag);
180 xml->tag.set_title(string);
182 xml->append_newline();
183 xml->append_newline();
187 int Labels::copy_length(long start, long end) // return number of Labels in selection
192 for(current = label_of(start); current && current->position <= end; current = NEXT)
199 void Labels::copy_from(Labels *labels)
201 while(last) delete last;
203 for(Label *current = labels->first; current; current = NEXT)
205 append(new Label(edl, this, current->position));
210 Labels& Labels::operator=(Labels &that)
213 printf("Labels::operator= 1\n");
218 int Labels::save(FileXML *xml)
220 xml->tag.set_title("LABELS");
222 xml->append_newline();
226 for(current = first; current; current = NEXT)
228 xml->tag.set_title("LABEL");
229 xml->tag.set_property("SAMPLE", (double)current->position);
233 xml->append_newline();
234 xml->tag.set_title("/LABELS");
236 xml->append_newline();
237 xml->append_newline();
241 int Labels::load(FileXML *xml, uint32_t load_flags)
244 char string1[BCTEXTLEN], string2[BCTEXTLEN];
246 sprintf(string1, "/%s", xml_tag);
247 strcpy(string2, xml_tag);
248 string2[strlen(string2) - 1] = 0;
251 result = xml->read_tag();
254 if(xml->tag.title_is(string1))
259 if(xml->tag.title_is(string2))
261 double position = xml->tag.get_property("SAMPLE", (double)-1);
262 //printf("Labels::load %f\n", position);
265 Label *current = label_of(position);
266 current = insert_before(current, new Label(edl, this, position));
270 if(xml->tag.title_is("INPOINT"))
272 double position = xml->tag.get_property("SAMPLE", (double)-1);
279 if(xml->tag.title_is("OUTPOINT"))
281 double position = xml->tag.get_property("SAMPLE", (double)-1);
294 int Labels::clear(double start, double end, int follow)
299 //printf("Labels::clear 1\n");
300 current = label_of(start);
301 //printf("Labels::clear 2\n");
302 // remove selected labels
303 while(current && current->position < end)
309 // Shift later labels
310 //printf("Labels::clear 3\n");
315 current->position -= end - start; // shift labels forward
318 //printf("Labels::clear 4\n");
320 //printf("Labels::clear 5\n");
327 Label* Labels::prev_label(double position)
331 // Test for label under cursor position
333 current && !edl->equivalent(current->position, position);
337 // Test for label after cursor position
340 current && current->position < position;
344 // Test for label before cursor position
348 // Get previous label
354 Label* Labels::next_label(double position)
358 // Test for label under cursor position
360 current && !edl->equivalent(current->position, position);
364 // Test for label before cursor position
367 current && current->position > position;
371 // Test for label after cursor position
381 int Labels::insert(double start, double length)
382 { // shift every label including the first one back
385 for(current = label_of(start); current; current = NEXT)
387 current->position += length;
392 int Labels::paste_silence(double start, double end)
394 insert(start, end - start);
399 int Labels::modify_handles(double oldposition,
406 handle_mode == MOVE_ALL_EDITS)
408 if(currentend == 0) // left handle
410 if(newposition < oldposition)
412 insert(oldposition, oldposition - newposition); // shift all labels right
416 clear(oldposition, newposition); // clear selection
421 if(newposition < oldposition)
423 clear(newposition, oldposition);
427 insert(oldposition, newposition - oldposition);
434 int Labels::optimize()
443 for(current = first; current && NEXT && !result;)
446 if(current->position == next->position)
457 Label* Labels::label_of(double position)
461 for(current = first; current; current = NEXT)
463 if(current->position >= position) return current;
482 Label::Label(EDL *edl, Labels *labels, double position)
486 this->labels = labels;
487 this->position = position;
493 // if(toggle) delete toggle;
496 LabelToggle::LabelToggle(MWindow *mwindow,
503 this->mwindow = mwindow;
507 LabelToggle::~LabelToggle() { }
509 int LabelToggle::handle_event()