[beast: 14/26] BSE: move all Song methods into bseapi.idl
- From: Tim Janik <timj src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [beast: 14/26] BSE: move all Song methods into bseapi.idl
- Date: Fri, 14 Oct 2016 15:49:10 +0000 (UTC)
commit f066b15821c3a408bd4f23c89e31838c5b6f5054
Author: Tim Janik <timj gnu org>
Date: Sun May 29 15:21:21 2016 +0200
BSE: move all Song methods into bseapi.idl
Signed-off-by: Tim Janik <timj gnu org>
bse/Makefile.am | 2 +-
bse/bseapi.idl | 11 ++-
bse/bsesong.cc | 106 +++++++++++++++++++++++++
bse/bsesong.hh | 5 +
bse/bsesong.proc | 225 ------------------------------------------------------
5 files changed, 118 insertions(+), 231 deletions(-)
---
diff --git a/bse/Makefile.am b/bse/Makefile.am
index 50b1f24..95e249b 100644
--- a/bse/Makefile.am
+++ b/bse/Makefile.am
@@ -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)
diff --git a/bse/bseapi.idl b/bse/bseapi.idl
index b93df61..ded23ac 100644
--- a/bse/bseapi.idl
+++ b/bse/bseapi.idl
@@ -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);
diff --git a/bse/bsesong.cc b/bse/bsesong.cc
index c55b7b4..fe66573 100644
--- a/bse/bsesong.cc
+++ b/bse/bsesong.cc
@@ -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
diff --git a/bse/bsesong.hh b/bse/bsesong.hh
index dc8899b..de7a0e5 100644
--- a/bse/bsesong.hh
+++ b/bse/bsesong.hh
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]