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, "/%s", xml_tag);
168 string[strlen(string) - 1] = 0; // remove trailing "S" on "LABELS" giving "LABEL"
169 for(current = label_of(start);
170 current && current->position <= end;
173 xml->tag.set_title(string+1); // skip the "/" for opening tag
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);
178 xml->tag.set_title(string); // closing tag
180 xml->append_newline();
183 sprintf(string, "/%s", xml_tag);
184 xml->tag.set_title(string);
186 xml->append_newline();
187 xml->append_newline();
191 int Labels::copy_length(long start, long end) // return number of Labels in selection
196 for(current = label_of(start); current && current->position <= end; current = NEXT)
203 void Labels::copy_from(Labels *labels)
205 while(last) delete last;
207 for(Label *current = labels->first; current; current = NEXT)
209 append(new Label(edl, this, current->position, current->textstr));
214 Labels& Labels::operator=(Labels &that)
217 printf("Labels::operator= 1\n");
222 int Labels::save(FileXML *xml)
223 // Note: Normally the saving of Labels is done by Labels::copy()
225 xml->tag.set_title("LABELS");
227 xml->append_newline();
231 for(current = first; current; current = NEXT)
233 xml->tag.set_title("LABEL");
234 xml->tag.set_property("TIME", (double)current->position);
235 xml->tag.set_property("TEXTSTR", current->textstr);
237 xml->tag.set_title("/LABEL");
239 xml->append_newline();
242 xml->append_newline();
243 xml->tag.set_title("/LABELS");
245 xml->append_newline();
246 xml->append_newline();
250 int Labels::load(FileXML *xml, uint32_t load_flags)
253 char string1[BCTEXTLEN], string2[BCTEXTLEN];
255 sprintf(string1, "/%s", xml_tag);
256 strcpy(string2, xml_tag);
257 string2[strlen(string2) - 1] = 0;
260 result = xml->read_tag();
263 if(xml->tag.title_is(string1))
268 if(xml->tag.title_is(string2))
270 double position = xml->tag.get_property("TIME", (double)-1);
272 position = xml->tag.get_property("SAMPLE", (double)-1);
273 //printf("Labels::load %f\n", position);
276 Label *current = label_of(position);
277 current = insert_before(current, new Label(edl, this, position, ""));
278 xml->tag.get_property("TEXTSTR", current->textstr);
282 if(xml->tag.title_is("INPOINT"))
284 double position = xml->tag.get_property("TIME", (double)-1);
286 position = xml->tag.get_property("SAMPLE", (double)-1);
293 if(xml->tag.title_is("OUTPOINT"))
295 double position = xml->tag.get_property("TIME", (double)-1);
297 position = xml->tag.get_property("SAMPLE", (double)-1);
310 int Labels::clear(double start, double end, int follow)
315 //printf("Labels::clear 1\n");
316 current = label_of(start);
317 //printf("Labels::clear 2\n");
318 // remove selected labels
319 while(current && current->position < end)
325 // Shift later labels
326 //printf("Labels::clear 3\n");
331 current->position -= end - start; // shift labels forward
334 //printf("Labels::clear 4\n");
336 //printf("Labels::clear 5\n");
343 Label* Labels::prev_label(double position)
347 // Test for label under cursor position
349 current && !edl->equivalent(current->position, position);
353 // Test for label after cursor position
356 current && current->position < position;
360 // Test for label before cursor position
364 // Get previous label
370 Label* Labels::next_label(double position)
374 // Test for label under cursor position
376 current && !edl->equivalent(current->position, position);
380 // Test for label before cursor position
383 current && current->position > position;
387 // Test for label after cursor position
397 int Labels::insert(double start, double length)
398 { // shift every label including the first one back
401 for(current = label_of(start); current; current = NEXT)
403 current->position += length;
408 int Labels::paste_silence(double start, double end)
410 insert(start, end - start);
415 int Labels::modify_handles(double oldposition,
422 handle_mode == MOVE_ALL_EDITS)
424 if(currentend == 0) // left handle
426 if(newposition < oldposition)
428 insert(oldposition, oldposition - newposition); // shift all labels right
432 clear(oldposition, newposition); // clear selection
437 if(newposition < oldposition)
439 clear(newposition, oldposition);
443 insert(oldposition, newposition - oldposition);
450 int Labels::optimize()
459 for(current = first; current && NEXT && !result;)
462 if(current->position == next->position)
473 Label* Labels::label_of(double position)
477 for(current = first; current; current = NEXT)
479 if(current->position >= position) return current;
498 Label::Label(EDL *edl, Labels *labels, double position, char *textstr = 0)
502 this->labels = labels;
503 this->position = position;
505 strcpy(this->textstr, textstr);
507 strcpy(this->textstr, "");
513 // if(toggle) delete toggle;
516 LabelToggle::LabelToggle(MWindow *mwindow,
523 this->mwindow = mwindow;
527 LabelToggle::~LabelToggle() { }
529 int LabelToggle::handle_event()
537 // c-file-style: "linux"