[beast: 22/26] BSE: move PartLinkSeq into bseapi.idl



commit 65bc0db3daadbe93933fa5af48b19ecdbfaa2afd
Author: Tim Janik <timj gnu org>
Date:   Fri Jul 3 12:38:05 2015 +0200

    BSE: move PartLinkSeq into bseapi.idl

 beast-gtk/bstpianoroll.cc |   34 +++++++++--------------
 beast-gtk/bstpianoroll.hh |    2 +-
 bse/Makefile.am           |    2 +-
 bse/bseapi.idl            |   19 +++++++++++++
 bse/bsebasics.idl         |   10 -------
 bse/bsepart.cc            |   65 +++++++++++++++++++++++++-------------------
 bse/bsepart.hh            |    3 +-
 bse/bsepart.proc          |   34 -----------------------
 8 files changed, 74 insertions(+), 95 deletions(-)
---
diff --git a/beast-gtk/bstpianoroll.cc b/beast-gtk/bstpianoroll.cc
index 81b2572..35cc771 100644
--- a/beast-gtk/bstpianoroll.cc
+++ b/beast-gtk/bstpianoroll.cc
@@ -134,6 +134,7 @@ static void
 bst_piano_roll_init (BstPianoRoll *self)
 {
   new (&self->part) Bse::PartH();
+  new (&self->plinks) Bse::PartLinkSeq();
   GxkScrollCanvas *scc = GXK_SCROLL_CANVAS (self);
 
   GTK_WIDGET_SET_FLAGS (self, GTK_CAN_FOCUS);
@@ -192,6 +193,7 @@ bst_piano_roll_finalize (GObject *object)
   G_OBJECT_CLASS (bst_piano_roll_parent_class)->finalize (object);
   using namespace Bse;
   self->part.~PartH();
+  self->plinks.~PartLinkSeq();
 }
 
 static void
@@ -1124,24 +1126,23 @@ piano_roll_handle_drag (GxkScrollCanvas     *scc,
 }
 
 static void
-piano_roll_song_pointer_changed (BstPianoRoll *self,
-                                 SfiInt        position)
+piano_roll_song_pointer_changed (BstPianoRoll *self, SfiInt position)
 {
-  BsePartLink *plink = NULL;
-  if (self->plinks && position >= 0)
+  Bse::PartLink *plink = NULL;
+  if (self->plinks.size() && position >= 0)
     {
       /* find size via binary lookup */
-      guint offset = 0, n_elements = self->plinks->n_plinks;
+      size_t offset = 0, n_elements = self->plinks.size();
       while (offset < n_elements)
         {
           guint i = (offset + n_elements) >> 1;
-          BsePartLink *current = self->plinks->plinks[i];
-          gint cmp = position < current->tick ? -1 : position > current->tick;
+          Bse::PartLink &current = self->plinks[i];
+          gint cmp = position < current.tick ? -1 : position > current.tick;
           if (cmp > 0) /* clamp to within duration */
-            cmp = position < current->tick + current->duration ? 0 : 1;
+            cmp = position < current.tick + current.duration ? 0 : 1;
           if (cmp == 0)
             {
-              plink = current;
+              plink = &current;
               break;
             }
           else if (cmp < 0)
@@ -1159,15 +1160,10 @@ piano_roll_song_pointer_changed (BstPianoRoll *self,
 static void
 piano_roll_links_changed (BstPianoRoll *self)
 {
-  if (self->plinks)
-    bse_part_link_seq_free (self->plinks);
-  self->plinks = NULL;
   if (self->part)
-    {
-      self->plinks = bse_part_list_links (self->part.proxy_id());
-      if (self->plinks)
-        self->plinks = bse_part_link_seq_copy_shallow (self->plinks);
-    }
+    self->plinks = self->part.list_links();
+  else
+    self->plinks.clear();
 }
 
 static void
@@ -1216,9 +1212,7 @@ bst_piano_roll_set_part (BstPianoRoll *self, Bse::PartH part)
           bse_item_unuse (self->song);
           self->song = 0;
         }
-      if (self->plinks)
-        bse_part_link_seq_free (self->plinks);
-      self->plinks = NULL;
+      self->plinks.clear();
       bse_proxy_disconnect (self->part.proxy_id(),
                            "any_signal", piano_roll_release_proxy, self,
                            "any_signal", piano_roll_range_changed, self,
diff --git a/beast-gtk/bstpianoroll.hh b/beast-gtk/bstpianoroll.hh
index 4885c98..01df588 100644
--- a/beast-gtk/bstpianoroll.hh
+++ b/beast-gtk/bstpianoroll.hh
@@ -44,7 +44,7 @@ struct _BstPianoRoll
 
   Bse::PartH     part;
   SfiProxy      song;
-  BsePartLinkSeq*plinks;
+  Bse::PartLinkSeq plinks;
   gint          min_note;
   gint          max_note;
   guint                 vzoom;
diff --git a/bse/Makefile.am b/bse/Makefile.am
index 6b4ea60..725e006 100644
--- a/bse/Makefile.am
+++ b/bse/Makefile.am
@@ -114,7 +114,7 @@ idl_dummy_files = $(strip   \
 # BSE procedure sources
 bse_proc_sources = $(strip \
        bsecategories.proc      bsecontainer.proc       bsedatapocket.proc      bseeditablesample.proc        
          bsemidinotifier.proc    \
-       bsejanitor.proc         bsepart.proc            bseparasite.proc        bseprocedure.proc       
bseproject.proc bsescripthelper.proc    \
+       bsejanitor.proc                                 bseparasite.proc        bseprocedure.proc       
bseproject.proc bsescripthelper.proc    \
                                bsesong.proc            bsebus.proc             bsesource.proc                
          bsesnet.proc            \
        bsetrack.proc           bseitem.proc            bsewave.proc            bsewaveosc.proc         
bsewaverepo.proc                        \
 )
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index 3c6eb7d..abf25b0 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -332,6 +332,10 @@ record SongTiming {
   float64 stamp_ticks = Range ("Tick Increment", "Ticks per stamp increment (useful only during playback)", 
STANDARD, 1, MAXINT31, 12, 384);
 };
 
+// Forward declarations.
+record PartLink;
+sequence PartLinkSeq;
+
 /// Fundamental base type for all BSE objects.
 interface Object {
   String debug_name (); ///< Object name useful for debugging output.
@@ -406,6 +410,7 @@ interface Part : Item {
   PartNoteSeq list_selected_notes (); ///< List all currently selected notes.
   PartNoteSeq check_overlap       (int32 tick, int32 duration, int32 note); ///< Check whether a note would 
overlap with neighbours.
   PartNoteSeq get_notes           (int32 tick, int32 note); ///< Retrieve all notes at a specific frequency 
or crossing a tick.
+  PartLinkSeq list_links          (); ///< List all places where parts are used (linked) from tracks, sorted 
by tick.
 
   // signal void    range_changed             (int32 a, int32 b, int32 c, int32 d);
   // signal void    links_changed             ();
@@ -486,6 +491,20 @@ interface Track : ContextMerger {
   // property ItemSeq outputs;     ///< _("Mixer busses used as output for this track.")
 };
 
+/// Record representing the use of a Part within a Track at a specific position.
+record PartLink {
+  Track track;
+  int32 tick     = Range ("Tick", "", STANDARD, 0, MAXINT31, 384);
+  Part  part;
+  int32 duration = Range ("Duration", "", STANDARD, 0, MAXINT31, 384);
+  // int32 count; // 1 + repetitions
+};
+
+/// Sequence of PartLink records.
+sequence PartLinkSeq {
+  PartLink plinks;
+};
+
 /// Interface for effect stacks and per-track audio signal routing to the master output.
 interface Bus : SubSynth {
   ErrorType ensure_output    ();            ///< Ensure that a bus has an output connection.
diff --git a/bse/bsebasics.idl b/bse/bsebasics.idl
index d09b4fe..b6f3d17 100644
--- a/bse/bsebasics.idl
+++ b/bse/bsebasics.idl
@@ -393,16 +393,6 @@ sequence DotSeq {
 /* BSE Part structures */
 interface Part;
 interface Track;
-record PartLink {
-  Track track;
-  Int   tick     = SfiInt ("Tick", "", 0, 0, G_MAXINT, 384, STANDARD);
-  Part  part;
-  Int   duration = SfiInt ("Duration", "", 0, 0, G_MAXINT, 384, STANDARD);
-  // Int   count; /* 1 + repetitions */
-};
-sequence PartLinkSeq {
-  PartLink plinks;
-};
 /* BSE Track structures */
 record TrackPart {
   Int           tick     = SfiInt ("Tick", "", 0, 0, G_MAXINT, 384, STANDARD);
diff --git a/bse/bsepart.cc b/bse/bsepart.cc
index 79919eb..7760610 100644
--- a/bse/bsepart.cc
+++ b/bse/bsepart.cc
@@ -445,30 +445,32 @@ bse_part_links_changed (BsePart *self)
     }
 }
 
-static int
-part_link_compare (const void *p1,
-                   const void *p2)
-{
-  const BsePartLink *const*lp1 = (const BsePartLink *const*) p1;
-  const BsePartLink *const*lp2 = (const BsePartLink *const*) p2;
-  const BsePartLink *l1 = lp1[0];
-  const BsePartLink *l2 = lp2[0];
-  if (l1->tick == l2->tick)
-    {
-      if (l1->duration == l2->duration)
-        return l1->track < l2->track ? -1 : l1->track > l2->track;
-      else
-        return l1->duration < l2->duration ? -1 : 1;
-    }
-  else
-    return l1->tick < l2->tick ? -1 : 1;
-}
-
-BsePartLinkSeq*
+static bool
+part_link_lesser (const Bse::PartLink &a, const Bse::PartLink &b)
+{
+  if (a.tick != b.tick)
+    return a.tick < b.tick;
+  if (a.duration != b.duration)
+    return a.duration < b.duration;
+  //if (a.count != b.count)
+  //  return a.count < b.count;
+  int64_t aid, bid;
+  aid = a.track.get() ? a.track->proxy_id() : 0;
+  bid = b.track.get() ? b.track->proxy_id() : 0;
+  if (aid != bid)
+    return aid < bid;
+  aid = a.part.get() ? a.part->proxy_id() : 0;
+  bid = b.part.get() ? b.part->proxy_id() : 0;
+  if (aid != bid)
+    return aid < bid;
+  return false;
+}
+
+Bse::PartLinkSeq
 bse_part_list_links (BsePart *self)
 {
-  g_return_val_if_fail (BSE_IS_PART (self), NULL);
-  BsePartLinkSeq *pls = bse_part_link_seq_new ();
+  Bse::PartLinkSeq pls;
+  g_return_val_if_fail (BSE_IS_PART (self), pls);
   BseSong *song = (BseSong*) bse_item_get_super (BSE_ITEM (self));
   if (BSE_IS_SONG (song))
     {
@@ -477,19 +479,19 @@ bse_part_list_links (BsePart *self)
         {
           BseTrack *track = (BseTrack*) ring->data;
           BseTrackPartSeq *tps = bse_track_list_part (track, self);
-          for (uint i = 0; i < tps->n_tparts; i++)
+          for (size_t i = 0; i < tps->n_tparts; i++)
             {
               BseTrackPart *tp = tps->tparts[i];
-              BsePartLink pl;
-              pl.track = track;
+              Bse::PartLink pl;
+              pl.track = track->as<Bse::TrackIfaceP>();
               pl.tick = tp->tick;
-              pl.part = self;
+              pl.part = self->as<Bse::PartIfaceP>();
               pl.duration = tp->duration;
-              bse_part_link_seq_append (pls, &pl);
+              pls.push_back (pl);
             }
           bse_track_part_seq_free (tps);
         }
-      qsort (pls->plinks, pls->n_plinks, sizeof (pls->plinks[0]), part_link_compare);
+      stable_sort (pls.begin(), pls.end(), part_link_lesser);
     }
   return pls;
 }
@@ -2146,6 +2148,13 @@ PartImpl::get_channel_controls (int channel, int tick, int duration, MidiSignalT
   return bse_part_list_controls (self, channel, tick, duration, control_type);
 }
 
+PartLinkSeq
+PartImpl::list_links ()
+{
+  BsePart *self = as<BsePart*>();
+  return bse_part_list_links (self);
+}
+
 SongTiming
 PartImpl::get_timing (int tick)
 {
diff --git a/bse/bsepart.hh b/bse/bsepart.hh
index 9839d76..9a482da 100644
--- a/bse/bsepart.hh
+++ b/bse/bsepart.hh
@@ -62,7 +62,7 @@ typedef enum    /*< skip >*/
 void               bse_part_set_semitone_table        (BsePart           *self,
                                                        const double      *semitone_table);
 void               bse_part_links_changed             (BsePart           *self);
-BsePartLinkSeq*    bse_part_list_links                (BsePart           *self);
+Bse::PartLinkSeq   bse_part_list_links                (BsePart *self);
 gboolean           bse_part_delete_control            (BsePart           *self,
                                                        guint              id);
 gboolean           bse_part_delete_note               (BsePart           *self,
@@ -282,6 +282,7 @@ public:
   virtual PartControlSeq list_controls          (int tick, int duration, MidiSignalType control_type) 
override;
   virtual PartControlSeq get_channel_controls   (int channel, int tick, int duration, MidiSignalType 
control_type) override;
   virtual PartControlSeq get_controls           (int tick, MidiSignalType control_type) override;
+  virtual PartLinkSeq    list_links             () override;
   virtual SongTiming     get_timing             (int tick) override;
   virtual int            get_max_note           () override;
   virtual int            get_min_note           () override;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]