diff -ruN freecycle/src/dlsmanager.cpp freecycle.new/src/dlsmanager.cpp --- freecycle/src/dlsmanager.cpp 2005-10-03 18:21:41.000000000 +0000 +++ freecycle.new/src/dlsmanager.cpp 2006-12-28 19:56:52.000000000 +0000 @@ -24,23 +24,17 @@ void DLSManager::writeDLS2File(QString outputfileName,QStringList* filenames,QValueList bld){ char nb_keygroups=filenames->size(); qHeapSort(bld); - + IpatchFile *file; IpatchDLSFile *dlsfile; IpatchDLS2Sample *sample; - - IpatchConverter *conv; - GType convtype; GError *err = NULL; - char *name; /* initialize libInstPatch */ ipatch_init (); - IpatchDLS2* dls2=ipatch_dls2_new(); - - + /*create new DLS2 instrument (++ ref) */ IpatchDLS2Inst* inst = ipatch_dls2_inst_new (); /* set instrument name */ @@ -68,68 +62,40 @@ g_clear_error (&err); continue; } - /* lookup converter type for the given conversion (file -> DLS2Sample) */ - convtype = ipatch_find_converter (G_OBJECT_TYPE (file), - IPATCH_TYPE_DLS2_SAMPLE, - IPATCH_CONVERTER_FIND_PARENT, IPATCH_CONVERTER_FIND_PARENT); - if (!convtype) /* conversion type found? */ + + /* attempt to convert sample file to DLS sample object + * ++ ref */ + sample = (IpatchDLS2Sample *)ipatch_convert_object_to_type (G_OBJECT (file), IPATCH_TYPE_DLS2_SAMPLE, &err); + + if (!sample) { - fprintf (stderr, "Unable to convert file '%s', type %s to %s\n", - filename.ascii(), g_type_name (G_OBJECT_TYPE (file)), - g_type_name (IPATCH_TYPE_DLS2_SAMPLE)); + fprintf (stderr, "Failed to convert file '%s' to DLS2 sample: %s\n", + filename.ascii(), ipatch_gerror_message (err)); + g_clear_error (&err); g_object_unref (file); /* remove file reference */ continue; } - - sample = ipatch_dls2_sample_new (); /* ++ ref new DLS2 sample */ - - - conv = (IpatchConverter*)g_object_new (convtype, NULL); /* ++ ref new converter object */ - - /* set input and output object of converter */ - ipatch_converter_add_input (conv, G_OBJECT (file)); - ipatch_converter_add_output (conv, G_OBJECT (sample)); - - /* convert the sample file to a DLS2 sample */ - if (!ipatch_converter_convert (conv, &err)) - { - fprintf (stderr, - "Failed to convert sample file to DLS2 sample: %s\n", - ipatch_gerror_message (err)); - - g_clear_error (&err); - - g_object_unref (conv); /* -- unref converter */ - g_object_unref (sample); /* -- unref DLS2 sample */ - g_object_unref (file); /* -- unref file */ - - continue; - } - - g_object_unref (conv); /* -- unref the converter */ - + /* append sample to DLS2 (ensure that its name is unique) */ ipatch_container_add_unique (IPATCH_CONTAINER (dls2), IPATCH_ITEM (sample)); - g_object_get (sample, "name", &name, NULL); /* get the sample's name */ - //g_object_set (sample, "root-note", midiNote, NULL); /* set the sample's root-note */ - + g_object_set (sample, "root-note", midiNote, NULL); /* set the sample's root-note */ + /* create new instrument zone and link sample to it */ IpatchDLS2Region* region=ipatch_dls2_region_new(); - ipatch_dls2_region_set_sample(region,sample); + ipatch_dls2_region_set_sample (region,sample); ipatch_container_add (IPATCH_CONTAINER (inst), IPATCH_ITEM (region)); - - g_object_set(region,"key-range-low", midiNote, NULL); - g_object_set(region,"key-range-high", midiNote, NULL); - + IpatchRange* range=ipatch_range_new (midiNote, midiNote); + g_object_set(region,"key-range", range, NULL); + ipatch_range_free(range); + g_object_unref(region); g_object_unref (sample); /* -- unref DLS sample */ - g_free (name); /* free the name (returned from g_object_get) */ g_object_unref (file); /* -- unref file */ } g_object_unref (inst); /* -- unref DLS instrument */ @@ -147,32 +113,16 @@ return; } - - /* lookup converter type for DLS2 -> File (save) */ - convtype = ipatch_find_converter (IPATCH_TYPE_DLS2, IPATCH_TYPE_DLS_FILE, - IPATCH_CONVERTER_FIND_CHILD, IPATCH_CONVERTER_FIND_CHILD); - - if(convtype==0) cout<<"conftype null!\n"; - - conv = (IpatchConverter*) g_object_new (convtype, NULL); /* ++ ref new converter */ - - - /* set input and output objects of converter */ - ipatch_converter_add_input (conv, G_OBJECT (dls2)); - ipatch_converter_add_output (conv, G_OBJECT (dlsfile)); - cout<<"OK3\n"; - if (!ipatch_converter_convert (conv, &err)){ - fprintf (stderr, "Failed to save DLS2 to file: %s\n", + /* convert DLS2 object to DLS2 file (write it) */ + if (!ipatch_convert_objects (G_OBJECT (dls2), G_OBJECT (dlsfile), &err)) + { + fprintf (stderr, "Failed to save DLS to file: %s\n", ipatch_gerror_message (err)); g_clear_error (&err); - } - cout<<"OK4\n"; - g_object_unref (conv); /* -- unref converter */ + } + g_object_unref (dlsfile); /* -- unref DLS2 file */ g_object_unref (dls2); /* -- unref DLS2 object */ - cout<<"OK5\n"; - //return (0); /* we done, yeah! :) */ + //return (0); /* we done, yeah! :) */ } - - diff -ruN freecycle/src/gigamanager.cpp freecycle.new/src/gigamanager.cpp --- freecycle/src/gigamanager.cpp 2005-10-03 18:21:43.000000000 +0000 +++ freecycle.new/src/gigamanager.cpp 2006-12-26 18:39:03.000000000 +0000 @@ -30,7 +30,6 @@ IpatchGigSample *sample; IpatchGigRegion *region; IpatchConverter *conv; - GType convtype; GError *err = NULL; char *name; @@ -62,52 +61,21 @@ continue; } - /* lookup converter type for the given conversion (file -> GigSample) */ - - convtype = ipatch_find_converter (G_OBJECT_TYPE (file), - IPATCH_TYPE_GIG_SAMPLE, - IPATCH_CONVERTER_FIND_PARENT, - IPATCH_CONVERTER_FIND_PARENT); - - if (!convtype) /* conversion type found? */ - { - - fprintf (stderr, "Unable to convert file '%s', type %s to %s\n", - filename.ascii(), g_type_name (G_OBJECT_TYPE (file)), - g_type_name (IPATCH_TYPE_GIG_SAMPLE)); - - g_object_unref (file); /* remove file reference */ + /* attempt to convert file to GigSample */ + sample = (IpatchGigSample *)ipatch_convert_object_to_type (G_OBJECT (file), IPATCH_TYPE_GIG_SAMPLE, &err); - continue; - } - - sample = ipatch_gig_sample_new (); /* ++ ref new Giga sample */ - - - conv = (IpatchConverter*)g_object_new (convtype, NULL); /* ++ ref new converter object */ - - /* set input and output object of converter */ - ipatch_converter_add_input (conv, G_OBJECT (file)); - ipatch_converter_add_output (conv, G_OBJECT (sample)); - - /* convert the sample file to a Giga sample */ - if (!ipatch_converter_convert (conv, &err)) + if (!sample) { fprintf (stderr, - "Failed to convert sample file to Gig sample: %s\n", - ipatch_gerror_message (err)); - + "Failed to convert sample file '%s' to Gig sample: %s\n", + filename.ascii(), ipatch_gerror_message (err)); + g_clear_error (&err); - - g_object_unref (conv); /* -- unref converter */ - g_object_unref (sample); /* -- unref SoundFont sample */ g_object_unref (file); /* -- unref file */ continue; } - g_object_unref (conv); /* -- unref the converter */ - // region=ipatch_gig_region_new (); /* ++ ref new Giga region */ //ipatch_container_add (IPATCH_CONTAINER (inst), IPATCH_ITEM (region)); @@ -125,6 +93,3 @@ } } - - - diff -ruN freecycle/src/sf2manager.cpp freecycle.new/src/sf2manager.cpp --- freecycle/src/sf2manager.cpp 2005-10-03 18:21:43.000000000 +0000 +++ freecycle.new/src/sf2manager.cpp 2006-12-26 18:38:15.000000000 +0000 @@ -38,10 +38,7 @@ IpatchSF2Sample *sample; IpatchSF2Inst *inst; IpatchSF2Preset *preset; - IpatchConverter *conv; - GType convtype; GError *err = NULL; - char *name; /* initialize libInstPatch */ ipatch_init (); @@ -81,69 +78,39 @@ g_clear_error (&err); continue; } - /* lookup converter type for the given conversion (file -> SF2Sample) */ - convtype = ipatch_find_converter (G_OBJECT_TYPE (file), - IPATCH_TYPE_SF2_SAMPLE, - IPATCH_CONVERTER_FIND_PARENT, IPATCH_CONVERTER_FIND_PARENT); - if (!convtype) /* conversion type found? */ + + /* attempt to convert sample file to SoundFont sample object + * ++ ref */ + sample = (IpatchSF2Sample *)ipatch_convert_object_to_type (G_OBJECT (file), IPATCH_TYPE_SF2_SAMPLE, &err); + + if (!sample) { - fprintf (stderr, "Unable to convert file '%s', type %s to %s\n", - filename.ascii(), g_type_name (G_OBJECT_TYPE (file)), - g_type_name (IPATCH_TYPE_SF2_SAMPLE)); + fprintf (stderr, "Failed to convert file '%s' to SoundFont sample: %s\n", + filename.ascii(), ipatch_gerror_message (err)); + g_clear_error (&err); g_object_unref (file); /* remove file reference */ continue; } - - sample = ipatch_sf2_sample_new (); /* ++ ref new SoundFont sample */ - - - conv = (IpatchConverter*)g_object_new (convtype, NULL); /* ++ ref new converter object */ - - /* set input and output object of converter */ - ipatch_converter_add_input (conv, G_OBJECT (file)); - ipatch_converter_add_output (conv, G_OBJECT (sample)); - - /* convert the sample file to a SoundFont sample */ - if (!ipatch_converter_convert (conv, &err)) - { - fprintf (stderr, - "Failed to convert sample file to SoundFont sample: %s\n", - ipatch_gerror_message (err)); - - g_clear_error (&err); - - g_object_unref (conv); /* -- unref converter */ - g_object_unref (sample); /* -- unref SoundFont sample */ - g_object_unref (file); /* -- unref file */ - - continue; - } - - g_object_unref (conv); /* -- unref the converter */ - + /* append sample to SoundFont (ensure that its name is unique) */ ipatch_container_add_unique (IPATCH_CONTAINER (sf2), IPATCH_ITEM (sample)); - g_object_get (sample, "name", &name, NULL); /* get the sample's name */ - g_object_set (sample, "root-note", midiNote, NULL); /* set the sample's root-note */ + g_object_set (sample, "root-note", midiNote, NULL); /* set the sample's root-note */ /* create new instrument zone and link sample to it */ IpatchSF2IZone* zone=ipatch_sf2_izone_new(); - ipatch_sf2_zone_set_item (IPATCH_SF2_ZONE (zone), IPATCH_ITEM (sample)); + ipatch_sf2_zone_set_link_item (IPATCH_SF2_ZONE (zone), IPATCH_ITEM (sample)); ipatch_container_add (IPATCH_CONTAINER (inst), IPATCH_ITEM (zone)); - IpatchRange* range=ipatch_range_new(); - range->low=midiNote; - range->high=midiNote; + IpatchRange* range=ipatch_range_new (midiNote, midiNote); g_object_set(zone,"key-range", range, NULL); - ipatch_range_free(range); + g_object_unref(zone); g_object_unref (sample); /* -- unref SoundFont sample */ - g_free (name); /* free the name (returned from g_object_get) */ g_object_unref (file); /* -- unref file */ } g_object_unref (inst); /* -- unref SoundFont instrument */ @@ -161,25 +128,15 @@ return; } - - /* lookup converter type for SoundFont -> File (save) */ - convtype = ipatch_find_converter (IPATCH_TYPE_SF2, IPATCH_TYPE_FILE, - IPATCH_CONVERTER_FIND_CHILD, IPATCH_CONVERTER_FIND_CHILD); - - conv = (IpatchConverter*) g_object_new (convtype, NULL); /* ++ ref new converter */ - - /* set input and output objects of converter */ - ipatch_converter_add_input (conv, G_OBJECT (sf2)); - ipatch_converter_add_output (conv, G_OBJECT (sffile)); - - if (!ipatch_converter_convert (conv, &err)) + + /* convert SoundFont object to SoundFont file (write it) */ + if (!ipatch_convert_objects (G_OBJECT (sf2), G_OBJECT (sffile), &err)) { fprintf (stderr, "Failed to save SoundFont to file: %s\n", ipatch_gerror_message (err)); g_clear_error (&err); } - g_object_unref (conv); /* -- unref converter */ g_object_unref (sffile); /* -- unref SoundFont file */ g_object_unref (sf2); /* -- unref SoundFont object */