XML for set files - Alex
[terminatorX.git] / src / tX_sequencer.cc
index 3c0f3d7582e0211fd10fd9e7e181b9db179c64a4..685a8318635147090e60e54e2c6aca0f59d5e1fd 100644 (file)
@@ -230,45 +230,24 @@ void tX_sequencer :: delete_all_events_for_sp(tX_seqpar *sp)
 #endif                         
 }
 
-void tX_sequencer :: save(FILE *out)
-{
+void tX_sequencer :: save(FILE *rc, char *indent) {
        guint32 event_count;
        list <tX_event *> :: iterator song_event;
        
        event_count=song_list.size();
-       
-       fwrite((void *) &event_count,  sizeof(event_count), 1, out);
-       
-       for (song_event=song_list.begin(); song_event!=song_list.end(); song_event++)
-       {
-               (*song_event)->store(out);
-       }
-}
 
-void tX_sequencer :: load(FILE *in)
-{
-       guint32 event_count=0;
-       guint32 i;
-       tX_event *new_event=NULL;
-       
-       clear();
+       fprintf(rc, "%s<sequencer>\n", indent);
+       strcat(indent, "\t");
        
-       fread ((void *) &event_count, sizeof(event_count), 1, in);
-       
-       max_timestamp=0;
-       
-       for (i=0; i<event_count; i++)
-       {
-               new_event=new tX_event(in);
-               song_list.push_back(new_event);
+       for (song_event=song_list.begin(); song_event!=song_list.end(); song_event++) {
+               (*song_event)->store(rc, indent);
        }
        
-       start_timestamp=0;
-       current_timestamp=0;
-       
-       if (new_event) max_timestamp=new_event->get_timestamp();
+       indent[strlen(indent)-1]=0;
+       fprintf(rc, "%s</sequencer>\n", indent);
 }
 
+
 void tX_sequencer :: clear()
 {
        if (song_list.size()==0) return;
@@ -335,3 +314,22 @@ void tX_sequencer :: forward_to_start_timestamp(int dont_fake)
        while (gtk_events_pending()) gtk_main_iteration();
 }
 
+void tX_sequencer :: load(xmlDocPtr doc, xmlNodePtr node) {
+       tX_event *ev=NULL;
+       
+       max_timestamp=0;
+       
+       for (xmlNodePtr cur=node->xmlChildrenNode; cur!=NULL; cur=cur->next) {
+               if (cur->type == XML_ELEMENT_NODE) {
+                       if (xmlStrcmp(cur->name, (xmlChar *) "event")==0) {
+                               ev=new tX_event(doc, cur);
+                               song_list.push_back(ev);
+                       } else {
+                               tX_warning("unhandled sequencer element %s.", cur->name);
+                       }
+               }
+       }
+       
+       start_timestamp=0;
+       current_timestamp=0;
+}