BSE: move all Song methods into bseapi.idl
authorTim Janik <timj@gnu.org>
Sun, 29 May 2016 13:21:21 +0000 (15:21 +0200)
committerTim Janik <timj@gnu.org>
Wed, 12 Oct 2016 23:10:43 +0000 (01:10 +0200)
Signed-off-by: Tim Janik <timj@gnu.org>
bse/Makefile.am
bse/bseapi.idl
bse/bsesong.cc
bse/bsesong.hh
bse/bsesong.proc [deleted file]

index 50b1f24..95e249b 100644 (file)
@@ -117,7 +117,7 @@ idl_dummy_files = $(strip   \
 bse_proc_sources = $(strip \
        bseeditablesample.proc  \
        bsejanitor.proc                                                         bseproject.proc         \
-                               bsesong.proc                                    bsesource.proc          \
+                                                                               bsesource.proc          \
                                bseitem.proc                                    bsewaveosc.proc         \
 )
 bse_proc_gen_sources = $(bse_proc_sources:.proc=.genprc.cc)
index b93df61..ded23ac 100644 (file)
@@ -746,11 +746,12 @@ interface Song : SNet {
   void       remove_part             (Part part);   ///< Delete a Part from a Song.
   Track      create_track            ();            ///< Create a new Track for a Song.
   void       remove_track            (Track track); ///< Delete a Track from 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 synthesize_note (Track track, int32 duration, int32 note, int32 fine_tune, float64 velocity); ///< Synthesize a note on a song of an active project.
+  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.
+  /// Synthesize a note on a song of an active project.
+  void       synthesize_note         (Track track, int32 duration, int32 note, int32 fine_tune, float64 velocity);
   // signal void   pointer_changed (int32 a);
   // group _("Timing") {
   // int32   tpqn          = Range  ("Ticks", "Number of ticks per quarter note", STANDARD, 384, 384, 0, 384);
index c55b7b4..fe66573 100644 (file)
@@ -958,4 +958,110 @@ SongImpl::musical_tuning (MusicalTuning tuning)
     }
 }
 
+BusIfaceP
+SongImpl::ensure_master_bus ()
+{
+  BseSong *self = as<BseSong*>();
+  BseSource *child = bse_song_ensure_master (self);
+  return child->as<BusIfaceP>();
+}
+
+TrackIfaceP
+SongImpl::find_track_for_part (PartIface &part_iface)
+{
+  BseSong *self = as<BseSong*>();
+  BsePart *part = part_iface.as<BsePart*>();
+  BseTrack *track = NULL;
+  uint tick = 0;
+  for (SfiRing *ring = self->tracks_SL; ring; ring = sfi_ring_walk (ring, self->tracks_SL))
+    {
+      BseTrack *test_track = (BseTrack*) ring->data;
+      uint start;
+      if (bse_track_find_part (test_track, part, &start) &&
+         (!track || start < tick))
+       {
+         track = test_track;
+         tick = start;
+       }
+    }
+  return track ? track->as<TrackIfaceP>() : NULL;
+}
+
+BusIfaceP
+SongImpl::get_master_bus ()
+{
+  BseSong *self = as<BseSong*>();
+  BseBus *bus = bse_song_find_master (self);
+  return bus ? bus->as<BusIfaceP>() : NULL;
+}
+
+void
+SongImpl::synthesize_note (TrackIface &track_iface, int duration, int note, int fine_tune, double velocity)
+{
+  BseSong *self = as<BseSong*>();
+  BseTrack *track = track_iface.as<BseTrack*>();
+  if (BSE_SOURCE_PREPARED (self) && self->midi_receiver_SL)
+    {
+      double semitone_factor = bse_transpose_factor (self->musical_tuning, CLAMP (note, SFI_MIN_NOTE, SFI_MAX_NOTE) - SFI_KAMMER_NOTE);
+      double freq = BSE_KAMMER_FREQUENCY * semitone_factor * bse_cent_tune_fast (fine_tune);
+      SfiTime tstamp = Bse::TickStamp::current() + bse_engine_block_size () * 2;
+      BseMidiEvent *eon, *eoff;
+      eon  = bse_midi_event_note_on (track->midi_channel_SL, tstamp, freq, velocity);
+      eoff = bse_midi_event_note_off (track->midi_channel_SL, tstamp + duration, freq);
+      bse_midi_receiver_push_event (self->midi_receiver_SL, eon);
+      bse_midi_receiver_push_event (self->midi_receiver_SL, eoff);
+      bse_midi_receiver_process_events (self->midi_receiver_SL, tstamp + duration);
+      bse_project_keep_activated (BSE_PROJECT (BSE_ITEM (self)->parent), tstamp + duration);
+    }
+}
+
+static const gchar*
+orphans_track_name (void)
+{
+  /* TRANSLATORS: this is the name of the track that is used to automatically
+   * adopt orphan (unlinked) parts.
+   */
+  return _("Orphan Parts");
+}
+
+static BseTrack*
+bse_song_ensure_orphans_track_noundo (BseSong *self)
+{
+  for (SfiRing *ring = self->tracks_SL; ring; ring = sfi_ring_walk (ring, self->tracks_SL))
+    {
+      BseTrack *track = (BseTrack*) ring->data;
+      gboolean muted = FALSE;
+      g_object_get (track, "muted", &muted, NULL);
+      if (muted && g_object_get_data ((GObject*) track, "BseSong-orphan-track") == bse_song_ensure_orphans_track_noundo) /* detect orphan-parts track */
+        return track;
+    }
+  BseTrack *child = (BseTrack*) bse_container_new_child_bname (BSE_CONTAINER (self), BSE_TYPE_TRACK, orphans_track_name(), NULL);
+  g_object_set (child, "muted", TRUE, NULL); /* no undo */
+  g_object_set_data ((GObject*) child, "BseSong-orphan-track", (void*) bse_song_ensure_orphans_track_noundo); /* mark orphan-parts track */
+  return child;
+}
+
+void
+SongImpl::ensure_track_links ()
+{
+  BseSong *self = as<BseSong*>();
+  bool clear_undo = false;
+  for (SfiRing *ring = self->parts; ring; ring = sfi_ring_walk (ring, self->parts))
+    {
+      BsePart *part = (BsePart*) ring->data;
+      if (bse_song_find_first_track (self, part))
+        continue;
+      BseTrack *track = bse_song_ensure_orphans_track_noundo (self);
+      TrackImpl *trackimpl = track->as<TrackImpl*>();
+      trackimpl->insert_part (bse_track_get_last_tick (track), *part->as<PartImpl*>());
+      clear_undo = true;
+    }
+  if (clear_undo)
+    {
+      BseProject *project = bse_item_get_project (self);
+      if (project)
+        bse_project_clear_undo (project);
+    }
+}
+
 } // Bse
index dc8899b..de7a0e5 100644 (file)
@@ -87,6 +87,11 @@ public:
   virtual void              remove_part             (PartIface &part) override;
   virtual TrackIfaceP       create_track            () override;
   virtual void              remove_track            (TrackIface &track) override;
+  virtual BusIfaceP         ensure_master_bus       () override;
+  virtual void              ensure_track_links      () override;
+  virtual TrackIfaceP       find_track_for_part     (PartIface &part) override;
+  virtual BusIfaceP         get_master_bus          () override;
+  virtual void              synthesize_note         (TrackIface &track, int duration, int note, int fine_tune, double velocity) override;
 };
 
 } // Bse
diff --git a/bse/bsesong.proc b/bse/bsesong.proc
deleted file mode 100644 (file)
index c0885e6..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-// Licensed GNU LGPL v2.1 or later: http://www.gnu.org/licenses/lgpl.html
-#include <bse/bseplugin.hh>
-#include <bse/bseprocedure.hh>
-#include <bse/bsemathsignal.hh>
-#include <bse/bsesong.hh>
-#include <bse/bsebus.hh>
-#include <bse/bsepart.hh>
-#include <bse/bsetrack.hh>
-#include "bsemidireceiver.hh"
-#include "bseundostack.hh"
-#include "bseproject.hh"
-#include "gslcommon.hh"
-#include "bseengine.hh"
-#include "bsecxxplugin.hh"
-#include <string.h>
-#include "bsebuiltin_externs.cc"
-
-AUTHORS = "Tim Janik <timj@gtk.org>";
-LICENSE = "GNU Lesser General Public License";
-
-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,
-                                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++);
-  BseSource *child;
-
-  /* check parameters */
-  if (!BSE_IS_SONG (self))
-    return Bse::Error::PROC_PARAM_INVAL;
-
-  /* action */
-  child = bse_song_ensure_master (self);
-
-  /* set output parameters */
-  bse_value_set_object (out_values++, child);
-
-  return Bse::Error::NONE;
-}
-
-METHOD (BseSong, get-master-bus) {
-  HELP  = _("Retrieve master output bus of a song if it exists.");
-  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++);
-
-  /* check parameters */
-  if (!BSE_IS_SONG (self))
-    return Bse::Error::PROC_PARAM_INVAL;
-
-  /* action */
-  BseBus *bus = bse_song_find_master (self);
-
-  /* set output parameters */
-  bse_value_set_object (out_values++, bus);
-
-  return Bse::Error::NONE;
-}
-
-static const gchar*
-orphans_track_name (void)
-{
-  /* TRANSLATORS: this is the name of the track that is used to automatically
-   * adopt orphan (unlinked) parts.
-   */
-  return _("Orphan Parts");
-}
-
-static BseTrack*
-bse_song_ensure_orphans_track_noundo (BseSong *self)
-{
-  for (SfiRing *ring = self->tracks_SL; ring; ring = sfi_ring_walk (ring, self->tracks_SL))
-    {
-      BseTrack *track = (BseTrack*) ring->data;
-      gboolean muted = FALSE;
-      g_object_get (track, "muted", &muted, NULL);
-      if (muted && g_object_get_data ((GObject*) track, "BseSong-orphan-track") == bse_song_ensure_orphans_track_noundo) /* detect orphan-parts track */
-        return track;
-    }
-  BseTrack *child = (BseTrack*) bse_container_new_child_bname (BSE_CONTAINER (self), BSE_TYPE_TRACK, orphans_track_name(), NULL);
-  g_object_set (child, "muted", TRUE, NULL); /* no undo */
-  g_object_set_data ((GObject*) child, "BseSong-orphan-track", (void*) bse_song_ensure_orphans_track_noundo); /* mark orphan-parts track */
-  return child;
-}
-
-METHOD (BseSong, ensure-track-links) {
-  HELP  = _("Ensure that each part in a song is inserted into at least one track.");
-  IN    = bse_param_spec_object ("song", NULL, NULL,
-                                BSE_TYPE_SONG, 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++);
-
-  /* check parameters */
-  if (!BSE_IS_SONG (self))
-    return Bse::Error::PROC_PARAM_INVAL;
-
-  /* action */
-  gboolean clear_undo = FALSE;
-  SfiRing *ring;
-  for (ring = self->parts; ring; ring = sfi_ring_walk (ring, self->parts))
-    if (!bse_song_find_first_track (self, (BsePart*) ring->data))
-      {
-        BseTrack *track = bse_song_ensure_orphans_track_noundo (self);
-        bse_item_exec_void (track, "insert-part", bse_track_get_last_tick (track), ring->data);
-        clear_undo = TRUE;
-      }
-  if (clear_undo)
-    {
-      BseProject *project = bse_item_get_project (BSE_ITEM (self));
-      if (project)
-        bse_project_clear_undo (project);
-    }
-
-  return Bse::Error::NONE;
-}
-
-METHOD (BseSong, find-track-for-part) {
-  HELP  = _("Find a track suitable for playing notes of a given part.");
-  IN    = bse_param_spec_object ("song", "Song", NULL,
-                                BSE_TYPE_SONG, SFI_PARAM_STANDARD);
-  IN    = bse_param_spec_object ("part", "Part", NULL,
-                                BSE_TYPE_PART, SFI_PARAM_STANDARD);
-  OUT   = bse_param_spec_object ("track", "Track", NULL,
-                                BSE_TYPE_TRACK, 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++);
-  BsePart *part = (BsePart*) bse_value_get_object (in_values++);
-  BseTrack *track = NULL;
-  guint tick = 0;
-  SfiRing *ring;
-
-  /* check parameters */
-  if (!BSE_IS_SONG (self) || !BSE_IS_PART (part) ||
-      BSE_ITEM (part)->parent != BSE_ITEM (self))
-    return Bse::Error::PROC_PARAM_INVAL;
-
-  /* action */
-  for (ring = self->tracks_SL; ring; ring = sfi_ring_walk (ring, self->tracks_SL))
-    {
-      BseTrack *test_track = (BseTrack*) ring->data;
-      guint start;
-      if (bse_track_find_part (test_track, part, &start) &&
-         (!track || start < tick))
-       {
-         track = test_track;
-         tick = start;
-       }
-    }
-
-  /* set output parameters */
-  bse_value_set_object (out_values++, track);
-
-  return Bse::Error::NONE;
-}
-
-METHOD (BseSong, synthesize-note) {
-  HELP  = _("Synthesize a note on a song of an active project.");
-  IN    = bse_param_spec_object ("song", "Song", NULL,
-                                BSE_TYPE_SONG, SFI_PARAM_STANDARD);
-  IN    = bse_param_spec_object ("track", "Track", NULL,
-                                BSE_TYPE_TRACK, SFI_PARAM_STANDARD);
-  IN    = sfi_pspec_int ("duration", "Tick Duration", NULL,
-                        1, 1, BSE_PART_MAX_TICK, 384, SFI_PARAM_STANDARD);
-  IN    = bse_pspec_note_simple ("note", "Note", NULL,
-                                SFI_PARAM_STANDARD);
-  IN    = bse_param_spec_fine_tune ("fine_tune", "Fine Tune", "Fine tune in cents per semitone");
-  IN    = sfi_pspec_real ("velocity", "Velocity", NULL,
-                         1.0, 0, 1.0, 0.01,
-                         SFI_PARAM_STANDARD ":scale");
-} BODY (BseProcedureClass *proc,
-        const GValue      *in_values,
-        GValue            *out_values)
-{
-  /* extract parameter values */
-  BseSong *self = (BseSong*) bse_value_get_object (in_values++);
-  BseTrack *track    = (BseTrack*) bse_value_get_object (in_values++);
-  guint    duration  = sfi_value_get_int (in_values++);
-  gint     note      = sfi_value_get_note (in_values++);
-  gint     fine_tune = sfi_value_get_int (in_values++);
-  gfloat   velocity  = sfi_value_get_real (in_values++);
-
-  /* check parameters */
-  if (!BSE_IS_SONG (self) || !BSE_IS_TRACK (track) ||
-      BSE_ITEM (track)->parent != BSE_ITEM (self))
-    return Bse::Error::PROC_PARAM_INVAL;
-
-  /* action */
-  if (BSE_SOURCE_PREPARED (self) && self->midi_receiver_SL)
-    {
-      double semitone_factor = bse_transpose_factor (self->musical_tuning, CLAMP (note, SFI_MIN_NOTE, SFI_MAX_NOTE) - SFI_KAMMER_NOTE);
-      double freq = BSE_KAMMER_FREQUENCY * semitone_factor * bse_cent_tune_fast (fine_tune);
-      SfiTime tstamp = Bse::TickStamp::current() + bse_engine_block_size () * 2;
-      BseMidiEvent *eon, *eoff;
-      eon  = bse_midi_event_note_on (track->midi_channel_SL, tstamp, freq, velocity);
-      eoff = bse_midi_event_note_off (track->midi_channel_SL, tstamp + duration, freq);
-      bse_midi_receiver_push_event (self->midi_receiver_SL, eon);
-      bse_midi_receiver_push_event (self->midi_receiver_SL, eoff);
-      bse_midi_receiver_process_events (self->midi_receiver_SL, tstamp + duration);
-      bse_project_keep_activated (BSE_PROJECT (BSE_ITEM (self)->parent), tstamp + duration);
-    }
-
-  return Bse::Error::NONE;
-}