[beast: 18/26] BSE: SongImpl: port create_bus() and remove_bus()
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 18/26] BSE: SongImpl: port create_bus() and remove_bus()
- Date: Mon, 13 Jul 2015 02:27:58 +0000 (UTC)
commit acaf67c2e8cb5f5629d3a6fc3a9a112ce54e94bc
Author: Tim Janik <timj gnu org>
Date: Thu Jul 2 13:49:01 2015 +0200
BSE: SongImpl: port create_bus() and remove_bus()
beast-gtk/bstbusmixer.cc | 18 +++++------
beast-gtk/bstbusview.cc | 12 +++---
bse/bseapi.idl | 6 ++--
bse/bsesong.cc | 59 +++++++++++++++++++++++++++++++++--
bse/bsesong.hh | 2 +
bse/bsesong.proc | 77 ----------------------------------------------
6 files changed, 75 insertions(+), 99 deletions(-)
---
diff --git a/beast-gtk/bstbusmixer.cc b/beast-gtk/bstbusmixer.cc
index aea3d2e..f2fdb19 100644
--- a/beast-gtk/bstbusmixer.cc
+++ b/beast-gtk/bstbusmixer.cc
@@ -171,27 +171,25 @@ bus_mixer_action_exec (gpointer data,
{
BstBusMixer *self = BST_BUS_MIXER (data);
BstItemView *iview = BST_ITEM_VIEW (self);
- SfiProxy song = iview->container;
+ Bse::SongH song = Bse::SongH::down_cast (bse_server.from_proxy (iview->container));
switch (action)
{
- SfiProxy item;
case ACTION_ADD_BUS:
- bse_item_group_undo (song, "Create Bus");
- item = bse_song_create_bus (song);
{
- Bse::BusH bus = Bse::BusH::down_cast (bse_server.from_proxy (item));
+ bse_item_group_undo (song.proxy_id(), "Create Bus");
+ Bse::BusH bus = song.create_bus();
bus.ensure_output();
+ bse_item_ungroup_undo (song.proxy_id());
+ bst_item_view_select (iview, bus.proxy_id());
}
- bse_item_ungroup_undo (song);
- if (item)
- bst_item_view_select (iview, item);
break;
case ACTION_DELETE_BUS:
if (self->hbox && BST_IS_BUS_EDITOR (GTK_CONTAINER (self->hbox)->focus_child))
{
BstBusEditor *be = BST_BUS_EDITOR (GTK_CONTAINER (self->hbox)->focus_child);
- if (be->item != bse_song_get_master_bus (song))
- bse_song_remove_bus (song, be->item);
+ Bse::BusH bus = Bse::BusH::down_cast (bse_server.from_proxy (be->item));
+ if ((SfiProxy) bus.proxy_id() != bse_song_get_master_bus (song.proxy_id()))
+ song.remove_bus (bus);
}
break;
}
diff --git a/beast-gtk/bstbusview.cc b/beast-gtk/bstbusview.cc
index 1efa219..c74ae72 100644
--- a/beast-gtk/bstbusview.cc
+++ b/beast-gtk/bstbusview.cc
@@ -68,17 +68,17 @@ bus_view_action_exec (gpointer data,
{
BstBusView *self = BST_BUS_VIEW (data);
BstItemView *item_view = BST_ITEM_VIEW (self);
- SfiProxy song = item_view->container;
+ Bse::SongH song = Bse::SongH::down_cast (bse_server.from_proxy (item_view->container));
+ Bse::BusH bus;
switch (action)
{
- SfiProxy item;
case ACTION_ADD_BUS:
- item = bse_song_create_bus (song);
- bst_item_view_select (item_view, item);
+ bus = song.create_bus();
+ bst_item_view_select (item_view, bus.proxy_id());
break;
case ACTION_DELETE_BUS:
- item = bst_item_view_get_current (item_view);
- bse_song_remove_bus (song, item);
+ bus = Bse::BusH::down_cast (bse_server.from_proxy (bst_item_view_get_current (item_view)));
+ song.remove_bus (bus);
break;
}
gxk_widget_update_actions_downwards (self);
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index 2678e4a..78adccf 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -492,15 +492,15 @@ interface Bus : SubSynth {
/// Interface for Track and Part objects, as well as meta data for sequencing.
interface Song : SNet {
- Track find_any_track_for_part (Part part); ///< Find the first track that contains part,
suitable to check for orphan parts.
- // Bus create_bus (); ///< Create a new mixer bus for a Song.
+ Track find_any_track_for_part (Part part); ///< Find the first track that contains part, suitable
to check for orphan parts.
+ Bus create_bus (); ///< Create a new mixer bus for a Song.
+ void remove_bus (Bus bus); ///< Delete a mixer bus from a Song.
// Part create_part (); ///< Create a new Part in a Song.
// Track create_track (); ///< Create a new Track for a Song.
// Bus ensure_master_bus (); ///< Retrieve master output bus of a song, will
create one if it doesn't exist.
// void ensure_track_links (); ///< Ensure that each part in a song is inserted into
at least one track.
// Track find_track_for_part (Part part); ///< Find a track suitable for playing notes of a
given part.
// Bus get_master_bus (); ///< Retrieve master output bus of a song if it
exists.
- // void remove_bus (Bus bus); ///< Delete a mixer bus from a Song.
// void remove_part (Part part); ///< Delete a Part from a Song.
// void remove_track (Track track); ///< Delete a Track from a Song.
// SongTiming get_timing (int32 tick); ///< Retrieve song timing information at a specific
tick.
diff --git a/bse/bsesong.cc b/bse/bsesong.cc
index 9f9b161..4ff052f 100644
--- a/bse/bsesong.cc
+++ b/bse/bsesong.cc
@@ -626,13 +626,21 @@ master_bus_name (void)
BseSource*
bse_song_ensure_master (BseSong *self)
{
+ Bse::SongImpl *this_ = self->as<Bse::SongImpl*>();
BseSource *child = (BseSource*) bse_song_find_master (self);
if (!child)
{
- BseUndoStack *ustack = bse_item_undo_open (self, "create-master");
+ BseUndoStack *ustack = bse_item_undo_open (self, "Create Master");
child = (BseSource*) bse_container_new_child_bname (BSE_CONTAINER (self), BSE_TYPE_BUS,
master_bus_name(), NULL);
- g_object_set (child, "master-output", TRUE, NULL); /* no undo */
- bse_item_push_undo_proc (self, "remove-bus", child);
+ g_object_set (child, "master-output", TRUE, NULL); // not-undoable
+ Bse::BusImpl *bus = child->as<Bse::BusImpl*>();
+ Bse::ItemImpl::UndoDescriptor<Bse::BusImpl> bus_descriptor = this_->undo_descriptor (*bus);
+ auto lambda = [bus_descriptor] (Bse::SongImpl &self, BseUndoStack *ustack) -> Bse::ErrorType {
+ Bse::BusImpl &bus = self.undo_resolve (bus_descriptor);
+ self.remove_bus (bus);
+ return Bse::ERROR_NONE;
+ };
+ this_->push_undo ("Create Master", *this_, lambda);
bse_item_undo_close (ustack);
}
return child;
@@ -813,4 +821,49 @@ SongImpl::find_any_track_for_part (PartIface &part)
return track->as<TrackIfaceP> ();
}
+BusIfaceP
+SongImpl::create_bus ()
+{
+ BseSong *self = as<BseSong*>();
+ if (BSE_SOURCE_PREPARED (self))
+ return NULL;
+ BusImpl *bus = ((BseItem*) bse_container_new_child (BSE_CONTAINER (self), BSE_TYPE_BUS,
NULL))->as<BusImpl*>();
+ UndoDescriptor<BusImpl> bus_descriptor = undo_descriptor (*bus);
+ auto lambda = [bus_descriptor] (SongImpl &self, BseUndoStack *ustack) -> ErrorType {
+ BusImpl &bus = self.undo_resolve (bus_descriptor);
+ self.remove_bus (bus);
+ return ERROR_NONE;
+ };
+ push_undo ("Create Bus", *this, lambda);
+ return bus->as<BusIfaceP>();
+}
+
+void
+SongImpl::remove_bus (BusIface &bus_iface)
+{
+ BseSong *self = as<BseSong*>();
+ BusImpl *bus = dynamic_cast<BusImpl*> (&bus_iface);
+ return_unless (bus->parent() == this);
+ if (BSE_SOURCE_PREPARED (self))
+ return;
+ BseItem *child = bus->as<BseItem*>();
+ BseUndoStack *ustack = bse_item_undo_open (self, "Remove Bus");
+ // reset ::master-output property undoable
+ bse_item_set (child, "master-output", FALSE, NULL);
+ // resets ::master-output non-undoable
+ bse_container_uncross_undoable (BSE_CONTAINER (self), child);
+ // implement "undo" of bse_container_remove_backedup, i.e. redo
+ UndoDescriptor<BusImpl> bus_descriptor = undo_descriptor (*bus);
+ auto lambda = [bus_descriptor] (SongImpl &self, BseUndoStack *ustack) -> ErrorType {
+ BusImpl &bus = self.undo_resolve (bus_descriptor);
+ self.remove_bus (bus);
+ return ERROR_NONE;
+ };
+ push_undo_to_redo ("Remove Bus", *this, lambda);
+ // backup and remove (without redo queueing)
+ bse_container_remove_backedup (BSE_CONTAINER (self), child, ustack);
+ // done
+ bse_item_undo_close (ustack);
+}
+
} // Bse
diff --git a/bse/bsesong.hh b/bse/bsesong.hh
index 941d912..10ff7c1 100644
--- a/bse/bsesong.hh
+++ b/bse/bsesong.hh
@@ -79,6 +79,8 @@ protected:
public:
explicit SongImpl (BseObject*);
TrackIfaceP find_any_track_for_part (PartIface &part) override;
+ BusIfaceP create_bus () override;
+ void remove_bus (BusIface &bus) override;
};
} // Bse
diff --git a/bse/bsesong.proc b/bse/bsesong.proc
index 85aea90..693f122 100644
--- a/bse/bsesong.proc
+++ b/bse/bsesong.proc
@@ -17,83 +17,6 @@
AUTHORS = "Tim Janik <timj gtk org>";
LICENSE = "GNU Lesser General Public License";
-METHOD (BseSong, create-bus) {
- HELP = _("Create a new mixer bus for a Song.");
- IN = bse_param_spec_object ("song", NULL, NULL,
- BSE_TYPE_SONG, SFI_PARAM_STANDARD);
- OUT = bse_param_spec_object ("bus", NULL, NULL,
- BSE_TYPE_BUS, SFI_PARAM_STANDARD);
-} BODY (BseProcedureClass *proc,
- const GValue *in_values,
- GValue *out_values)
-{
- /* extract parameter values */
- BseSong *self = (BseSong*) bse_value_get_object (in_values++);
- Bse::ErrorType error = Bse::ERROR_NONE;
- BseUndoStack *ustack;
- BseItem *child = NULL;
-
- /* check parameters */
- if (!BSE_IS_SONG (self))
- return Bse::ERROR_PROC_PARAM_INVAL;
-
- /* action */
- if (BSE_SOURCE_PREPARED (self))
- error = Bse::ERROR_SOURCE_BUSY;
- else
- {
- ustack = bse_item_undo_open (self, "create-bus");
- child = (BseItem*) bse_container_new_child (BSE_CONTAINER (self), BSE_TYPE_BUS, NULL);
- bse_item_push_undo_proc (self, "remove-bus", child);
- bse_item_undo_close (ustack);
- }
-
- /* set output parameters */
- bse_value_set_object (out_values++, child);
-
- return error;
-}
-
-METHOD (BseSong, remove-bus) {
- HELP = _("Delete a mixer bus from a Song.");
- IN = bse_param_spec_object ("song", NULL, NULL,
- BSE_TYPE_SONG, SFI_PARAM_STANDARD);
- IN = bse_param_spec_object ("bus", NULL, NULL,
- BSE_TYPE_BUS, SFI_PARAM_STANDARD);
-} BODY (BseProcedureClass *proc,
- const GValue *in_values,
- GValue *out_values)
-{
- /* extract parameter values */
- BseSong *self = (BseSong*) bse_value_get_object (in_values++);
- BseItem *child = (BseItem*) bse_value_get_object (in_values++);
- Bse::ErrorType error = Bse::ERROR_NONE;
-
- /* check parameters */
- if (!BSE_IS_SONG (self) || !BSE_IS_BUS (child) || BSE_ITEM (child)->parent != BSE_ITEM (self))
- return Bse::ERROR_PROC_PARAM_INVAL;
-
- /* action */
- if (BSE_SOURCE_PREPARED (self))
- error = Bse::ERROR_SOURCE_BUSY;
- else
- {
- BseUndoStack *ustack = bse_item_undo_open (self, "remove-child %s", bse_object_debug_name (child));
- /* reset ::master-output property undoable */
- bse_item_set (child, "master-output", FALSE, NULL);
- /* remove and backup object references */
- bse_container_uncross_undoable (BSE_CONTAINER (self), child); /* resets ::master-output
non-undoable */
- /* how to get rid of the item once backed up */
- bse_item_push_redo_proc (self, "remove-bus", child);
- /* remove (without redo queueing) */
- bse_container_remove_backedup (BSE_CONTAINER (self), child, ustack);
- /* done */
- bse_item_undo_close (ustack);
- }
-
- return error;
-}
-
METHOD (BseSong, ensure-master-bus) {
HELP = _("Retrieve master output bus of a song, will create one if it doesn't exist.");
IN = bse_param_spec_object ("song", NULL, NULL,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]