/** * bt_wave_new: * @song: the song the new instance belongs to * @name: the display name for the new wave * @uri: the location of the sample data * @index: the list slot for the new wave * @volume: the volume of the wave * @loop_mode: loop playback mode * @channels: number of audio channels * * Create a new instance * * Returns: the new instance or %NULL in case of an error */ BtWave * bt_wave_new (const BtSong * const song, const gchar * const name, const gchar * const uri, const gulong index, const gdouble volume, const BtWaveLoopMode loop_mode, const guint channels) { return BT_WAVE (g_object_new (BT_TYPE_WAVE, "song", song, "name", name, "uri", uri, "index", index, "volume", volume, "loop-mode", loop_mode, "channels", channels, NULL)); }
static xmlNodePtr bt_wave_persistence_save (const BtPersistence * const persistence, const xmlNodePtr const parent_node) { const BtWave *const self = BT_WAVE (persistence); xmlNodePtr node = NULL; xmlNodePtr child_node; GST_DEBUG ("PERSISTENCE::wave"); if ((node = xmlNewChild (parent_node, NULL, XML_CHAR_PTR ("wave"), NULL))) { BtSongIONative *song_io; // we need to have a uri if (!self->priv->uri) self->priv->uri = g_strdup (self->priv->name); xmlNewProp (node, XML_CHAR_PTR ("index"), XML_CHAR_PTR (bt_str_format_ulong (self->priv->index))); xmlNewProp (node, XML_CHAR_PTR ("name"), XML_CHAR_PTR (self->priv->name)); xmlNewProp (node, XML_CHAR_PTR ("uri"), XML_CHAR_PTR (self->priv->uri)); xmlNewProp (node, XML_CHAR_PTR ("volume"), XML_CHAR_PTR (bt_str_format_double (self->priv->volume))); xmlNewProp (node, XML_CHAR_PTR ("loop-mode"), XML_CHAR_PTR (bt_str_format_enum (BT_TYPE_WAVE_LOOP_MODE, self->priv->loop_mode))); // check if we need to save external data g_object_get (self->priv->song, "song-io", &song_io, NULL); if (song_io) { if (BT_IS_SONG_IO_NATIVE_BZT (song_io)) { gchar *uri = NULL; if (self->priv->ext_fd == -1) { // need to write in memory data to a wav bt_wave_save_to_fd (self); } uri = g_strdup_printf ("fd://%d", self->priv->ext_fd); bt_wave_save_from_fd (self, song_io, uri); g_free (uri); } g_object_unref (song_io); } // save wavelevels if ((child_node = xmlNewChild (node, NULL, XML_CHAR_PTR ("wavelevels"), NULL))) { bt_persistence_save_list (self->priv->wavelevels, child_node); } } return node; }
/** * bt_wavetable_get_wave_by_index: * @self: the wavetable to search for the wave * @index: the index of the wave * * Search the wavetable for a wave by the supplied index. * The wave must have been added previously to this wavetable with * bt_wavetable_add_wave(). * * Returns: (transfer full): #BtWave instance or %NULL if not found. Unref the * wave, when done with it. */ BtWave * bt_wavetable_get_wave_by_index (const BtWavetable * const self, const gulong index) { const GList *node; gulong wave_index; g_assert (BT_IS_WAVETABLE (self)); for (node = self->priv->waves; node; node = g_list_next (node)) { BtWave *const wave = BT_WAVE (node->data); g_object_get (wave, "index", &wave_index, NULL); if (index == wave_index) return g_object_ref (wave); } return NULL; }
static BtPersistence * bt_wavetable_persistence_load (const GType type, const BtPersistence * const persistence, xmlNodePtr node, GError ** err, va_list var_args) { const BtWavetable *const self = BT_WAVETABLE (persistence); xmlNodePtr child_node; GST_DEBUG ("PERSISTENCE::wavetable"); g_assert (node); for (child_node = node->children; child_node; child_node = child_node->next) { if ((!xmlNodeIsText (child_node)) && (!strncmp ((char *) child_node->name, "wave\0", 5))) { GError *err = NULL; BtWave *const wave = BT_WAVE (bt_persistence_load (BT_TYPE_WAVE, NULL, child_node, &err, "song", self->priv->song, NULL)); if (err != NULL) { // collect failed waves gchar *const name, *const uri; g_object_get (wave, "name", &name, "uri", &uri, NULL); gchar *const str = g_strdup_printf ("%s: %s", name, uri); bt_wavetable_remember_missing_wave (self, str); g_free (name); g_free (uri); GST_WARNING ("Can't create wavetable: %s", err->message); g_error_free (err); } g_object_unref (wave); } } return BT_PERSISTENCE (persistence); }
static void bt_wavelevel_set_property (GObject * const object, const guint property_id, const GValue * const value, GParamSpec * const pspec) { const BtWavelevel *const self = BT_WAVELEVEL (object); return_if_disposed (); switch (property_id) { case WAVELEVEL_SONG: self->priv->song = BT_SONG (g_value_get_object (value)); g_object_try_weak_ref (self->priv->song); //GST_DEBUG("set the song for wavelevel: %p",self->priv->song); break; case WAVELEVEL_WAVE: self->priv->wave = BT_WAVE (g_value_get_object (value)); g_object_try_weak_ref (self->priv->wave); GST_DEBUG ("set the wave for wavelevel: %p", self->priv->wave); break; case WAVELEVEL_ROOT_NOTE: self->priv->root_note = g_value_get_enum (value); GST_DEBUG ("set the root-note for wavelevel: %d", self->priv->root_note); break; case WAVELEVEL_LENGTH: self->priv->length = g_value_get_ulong (value); GST_DEBUG ("set the length for wavelevel: %lu", self->priv->length); break; case WAVELEVEL_LOOP_START: self->priv->loop_start = g_value_get_ulong (value); GST_INFO ("loop: 0 / %lu .. %lu / %lu", self->priv->loop_start, self->priv->loop_end, self->priv->length); // make sure its less then loop_end/length if (self->priv->loop_end > 0) { if (self->priv->loop_start >= self->priv->loop_end) { GST_DEBUG ("clip loop-start by loop-end: %lu", self->priv->loop_end); self->priv->loop_start = self->priv->loop_end - 1; } } if (self->priv->length > 0) { if (self->priv->loop_start >= self->priv->length) { GST_DEBUG ("clip loop-start by length: %lu", self->priv->length); self->priv->loop_start = self->priv->length - 1; } } GST_DEBUG ("set the loop-start for wavelevel: %lu", self->priv->loop_start); break; case WAVELEVEL_LOOP_END: self->priv->loop_end = g_value_get_ulong (value); GST_INFO ("loop: 0 / %lu .. %lu / %lu", self->priv->loop_start, self->priv->loop_end, self->priv->length); // make sure its more then loop-start if (self->priv->loop_start > 0) { if (self->priv->loop_end < self->priv->loop_start) { GST_DEBUG ("clip loop-end by loop-start: %lu", self->priv->loop_start); self->priv->loop_end = self->priv->loop_start + 1; } } // make sure its less then or equal to length if (self->priv->length > 0) { if (self->priv->loop_end > self->priv->length) { GST_DEBUG ("clip loop-end by length: %lu", self->priv->length); self->priv->loop_end = self->priv->length; } } GST_DEBUG ("set the loop-start for wavelevel: %lu", self->priv->loop_start); break; case WAVELEVEL_RATE: self->priv->rate = g_value_get_ulong (value); GST_DEBUG ("set the rate for wavelevel: %lu", self->priv->rate); break; case WAVELEVEL_DATA: g_free (self->priv->sample); self->priv->sample = g_value_get_pointer (value); GST_DEBUG ("set the data-pointer for wavelevel: %p", self->priv->sample); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; } }