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)
201 Labels& Labels::operator=(Labels &that)
203 while(last) delete last;
205 for(Label *current = that.first; current; current = NEXT)
207 append(new Label(edl, this, current->position));
214 int Labels::save(FileXML *xml)
216 xml->tag.set_title("LABELS");
218 xml->append_newline();
222 for(current = first; current; current = NEXT)
224 xml->tag.set_title("LABEL");
225 xml->tag.set_property("SAMPLE", (double)current->position);
229 xml->append_newline();
230 xml->tag.set_title("/LABELS");
232 xml->append_newline();
233 xml->append_newline();
237 int Labels::load(FileXML *xml, uint32_t load_flags)
240 char string1[BCTEXTLEN], string2[BCTEXTLEN];
242 sprintf(string1, "/%s", xml_tag);
243 strcpy(string2, xml_tag);
244 string2[strlen(string2) - 1] = 0;
247 result = xml->read_tag();
250 if(xml->tag.title_is(string1))
255 if(xml->tag.title_is(string2))
257 double position = xml->tag.get_property("SAMPLE", (double)-1);
258 //printf("Labels::load %f\n", position);
261 Label *current = label_of(position);
262 current = insert_before(current, new Label(edl, this, position));
266 if(xml->tag.title_is("INPOINT"))
268 double position = xml->tag.get_property("SAMPLE", (double)-1);
275 if(xml->tag.title_is("OUTPOINT"))
277 double position = xml->tag.get_property("SAMPLE", (double)-1);
290 int Labels::clear(double start, double end, int follow)
295 //printf("Labels::clear 1\n");
296 current = label_of(start);
297 //printf("Labels::clear 2\n");
298 // remove selected labels
299 while(current && current->position < end)
305 // Shift later labels
306 //printf("Labels::clear 3\n");
311 current->position -= end - start; // shift labels forward
314 //printf("Labels::clear 4\n");
316 //printf("Labels::clear 5\n");
323 Label* Labels::prev_label(double position)
327 // Test for label under cursor position
329 current && !edl->equivalent(current->position, position);
333 // Test for label after cursor position
336 current && current->position < position;
340 // Test for label before cursor position
344 // Get previous label
350 Label* Labels::next_label(double position)
354 // Test for label under cursor position
356 current && !edl->equivalent(current->position, position);
360 // Test for label before cursor position
363 current && current->position > position;
367 // Test for label after cursor position
377 int Labels::insert(double start, double length)
378 { // shift every label including the first one back
381 for(current = label_of(start); current; current = NEXT)
383 current->position += length;
388 int Labels::paste_silence(double start, double end)
390 insert(start, end - start);
395 int Labels::modify_handles(double oldposition,
402 handle_mode == MOVE_ALL_EDITS)
404 if(currentend == 0) // left handle
406 if(newposition < oldposition)
408 insert(oldposition, oldposition - newposition); // shift all labels right
412 clear(oldposition, newposition); // clear selection
417 if(newposition < oldposition)
419 clear(newposition, oldposition);
423 insert(oldposition, newposition - oldposition);
430 int Labels::optimize()
439 for(current = first; current && NEXT && !result;)
442 if(current->position == next->position)
453 Label* Labels::label_of(double position)
457 for(current = first; current; current = NEXT)
459 if(current->position >= position) return current;
478 Label::Label(EDL *edl, Labels *labels, double position)
482 this->labels = labels;
483 this->position = position;
489 // if(toggle) delete toggle;
492 LabelToggle::LabelToggle(MWindow *mwindow,
499 this->mwindow = mwindow;
503 LabelToggle::~LabelToggle() { }
505 int LabelToggle::handle_event()