diff options
author | Carl Hetherington <carl@carlh.net> | 2010-10-08 14:54:16 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2010-10-08 14:54:16 +0000 |
commit | ba0458cf1f6c69366e89631d8fff916ad183d768 (patch) | |
tree | 47bc77224638eac6d7a9e8179e03e5fa0a142665 | |
parent | a029a112a6e370082e89b74cb94089505a9323af (diff) |
Update recorded MIDI regions as notes arrive. Fixes one cause of infinite note-lengths during record. Fix various problems with multiple captures of MIDI during one pass.
git-svn-id: svn://localhost/ardour2/branches/3.0@7887 d708f5d6-7413-0410-9779-e7cbd77b26cf
-rw-r--r-- | gtk2_ardour/audio_streamview.cc | 2 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.cc | 63 | ||||
-rw-r--r-- | gtk2_ardour/midi_region_view.h | 5 | ||||
-rw-r--r-- | gtk2_ardour/midi_streamview.cc | 202 | ||||
-rw-r--r-- | gtk2_ardour/midi_streamview.h | 14 | ||||
-rw-r--r-- | gtk2_ardour/streamview.cc | 2 | ||||
-rw-r--r-- | gtk2_ardour/streamview.h | 2 | ||||
-rw-r--r-- | libs/ardour/ardour/diskstream.h | 13 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_diskstream.h | 6 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_source.h | 6 | ||||
-rw-r--r-- | libs/ardour/ardour/midi_track.h | 5 | ||||
-rwxr-xr-x | libs/ardour/ardour/public_diskstream.h | 4 | ||||
-rw-r--r-- | libs/ardour/ardour/track.h | 4 | ||||
-rw-r--r-- | libs/ardour/diskstream.cc | 17 | ||||
-rw-r--r-- | libs/ardour/midi_diskstream.cc | 33 | ||||
-rw-r--r-- | libs/ardour/midi_track.cc | 11 | ||||
-rw-r--r-- | libs/ardour/smf_source.cc | 2 | ||||
-rw-r--r-- | libs/ardour/track.cc | 4 |
18 files changed, 169 insertions, 226 deletions
diff --git a/gtk2_ardour/audio_streamview.cc b/gtk2_ardour/audio_streamview.cc index b6c29670cd..4b2033ff63 100644 --- a/gtk2_ardour/audio_streamview.cc +++ b/gtk2_ardour/audio_streamview.cc @@ -497,7 +497,7 @@ AudioStreamView::setup_rec_box () boost::shared_ptr<AudioTrack> at; at = _trackview.audio_track(); /* we know what it is already */ - nframes_t frame_pos = at->current_capture_start (); + framepos_t const frame_pos = at->current_capture_start (); gdouble xstart = _trackview.editor().frame_to_pixel (frame_pos); gdouble xend; uint32_t fill_color; diff --git a/gtk2_ardour/midi_region_view.cc b/gtk2_ardour/midi_region_view.cc index 400b245782..ffc9fcac75 100644 --- a/gtk2_ardour/midi_region_view.cc +++ b/gtk2_ardour/midi_region_view.cc @@ -103,6 +103,8 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView & { _note_group->raise_to_top(); PublicEditor::DropDownKeys.connect (sigc::mem_fun (*this, &MidiRegionView::drop_down_keys)); + + connect_to_diskstream (); } MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView &tv, @@ -127,6 +129,8 @@ MidiRegionView::MidiRegionView (ArdourCanvas::Group *parent, RouteTimeAxisView & { _note_group->raise_to_top(); PublicEditor::DropDownKeys.connect (sigc::mem_fun (*this, &MidiRegionView::drop_down_keys)); + + connect_to_diskstream (); } MidiRegionView::MidiRegionView (const MidiRegionView& other) @@ -232,6 +236,14 @@ MidiRegionView::init (Gdk::Color const & basic_color, bool wfd) sigc::mem_fun(this, &MidiRegionView::midi_patch_settings_changed)); trackview.editor().SnapChanged.connect (snap_changed_connection, invalidator (*this), ui_bind (&MidiRegionView::snap_changed, this), gui_context ()); + + connect_to_diskstream (); +} + +void +MidiRegionView::connect_to_diskstream () +{ + midi_view()->midi_track()->DataRecorded.connect (*this, invalidator (*this), ui_bind (&MidiRegionView::data_recorded, this, _1, _2), gui_context ()); } bool @@ -734,11 +746,11 @@ MidiRegionView::clear_events() _optimization_iterator = _events.end(); } - void MidiRegionView::display_model(boost::shared_ptr<MidiModel> model) { _model = model; + content_connection.disconnect (); _model->ContentsChanged.connect (content_connection, invalidator (*this), boost::bind (&MidiRegionView::redisplay_model, this), gui_context()); @@ -1287,7 +1299,7 @@ MidiRegionView::resolve_note(uint8_t note, double end_time) } if (_active_notes && _active_notes[note]) { - const framepos_t end_time_frames = beats_to_frames(end_time); + const framepos_t end_time_frames = beats_to_frames(end_time) - _region->start(); _active_notes[note]->property_x2() = trackview.editor().frame_to_pixel(end_time_frames); _active_notes[note]->property_outline_what() = (guint32) 0xF; // all edges _active_notes[note] = 0; @@ -3114,3 +3126,50 @@ MidiRegionView::set_step_edit_cursor_width (Evoral::MusicalTime beats) } } +/** Called when a diskstream on our track has received some data. Update the view, if applicable. + * @param buf Data that has been recorded. + * @param w Source that this data will end up in. + */ +void +MidiRegionView::data_recorded (boost::shared_ptr<MidiBuffer> buf, boost::weak_ptr<MidiSource> w) +{ + if (!_active_notes) { + /* we aren't actively being recorded to */ + return; + } + + boost::shared_ptr<MidiSource> src = w.lock (); + if (!src || src != midi_region()->midi_source()) { + /* recorded data was not destined for our source */ + return; + } + + MidiTimeAxisView* mtv = dynamic_cast<MidiTimeAxisView*> (&trackview); + BeatsFramesConverter converter (trackview.session()->tempo_map(), mtv->midi_track()->get_capture_start_frame (0)); + + for (MidiBuffer::iterator i = buf->begin(); i != buf->end(); ++i) { + Evoral::MIDIEvent<MidiBuffer::TimeType> const ev (*i, false); + assert (ev.buffer ()); + + Evoral::MusicalTime const time_beats = converter.from (ev.time () - converter.origin_b ()); + + if (ev.type() == MIDI_CMD_NOTE_ON) { + + boost::shared_ptr<Evoral::Note<Evoral::MusicalTime> > note ( + new Evoral::Note<Evoral::MusicalTime> (ev.channel(), time_beats, 0, ev.note(), ev.velocity()) + ); + + add_note (note, true); + + /* fix up our note range */ + if (ev.note() < _current_range_min) { + midi_stream_view()->apply_note_range (ev.note(), _current_range_max, true); + } else if (ev.note() > _current_range_max) { + midi_stream_view()->apply_note_range (_current_range_min, ev.note(), true); + } + + } else if (ev.type() == MIDI_CMD_NOTE_OFF) { + resolve_note (ev.note (), time_beats); + } + } +} diff --git a/gtk2_ardour/midi_region_view.h b/gtk2_ardour/midi_region_view.h index d89f477145..5b01bcb7b8 100644 --- a/gtk2_ardour/midi_region_view.h +++ b/gtk2_ardour/midi_region_view.h @@ -395,7 +395,7 @@ class MidiRegionView : public RegionView std::vector<NoteResizeData *> _resize_data; - /* connection used to connect to model's ContentChanged signal */ + /** connection used to connect to model's ContentChanged signal */ PBD::ScopedConnection content_connection; ArdourCanvas::CanvasNoteEvent* find_canvas_note (boost::shared_ptr<NoteType>); @@ -432,6 +432,9 @@ class MidiRegionView : public RegionView void display_program_changes_on_channel (uint8_t); + void connect_to_diskstream (); + void data_recorded (boost::shared_ptr<ARDOUR::MidiBuffer>, boost::weak_ptr<ARDOUR::MidiSource>); + Gdk::Cursor* pre_enter_cursor; }; diff --git a/gtk2_ardour/midi_streamview.cc b/gtk2_ardour/midi_streamview.cc index 1604d4757d..ef625f0a1c 100644 --- a/gtk2_ardour/midi_streamview.cc +++ b/gtk2_ardour/midi_streamview.cc @@ -434,12 +434,6 @@ MidiStreamView::setup_rec_box () sources.push_back (_trackview.midi_track()->write_source()); - _trackview.midi_track()->write_source()->ViewDataRangeReady.connect - (rec_data_ready_connections, - invalidator (*this), - ui_bind (&MidiStreamView::rec_data_range_ready, this, _1, _2, boost::weak_ptr<Source>(_trackview.midi_track()->write_source())), - gui_context()); - // handle multi nframes_t start = 0; @@ -447,6 +441,11 @@ MidiStreamView::setup_rec_box () start = rec_regions.back().first->start() + _trackview.track()->get_captured_frames(rec_regions.size()-1); } + + if (!rec_regions.empty()) { + MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (rec_regions.back().second); + mrv->end_write (); + } PropertyList plist; @@ -459,8 +458,13 @@ MidiStreamView::setup_rec_box () (RegionFactory::create (sources, plist, false))); assert(region); - region->set_position (_trackview.session()->transport_frame(), this); - rec_regions.push_back (make_pair(region, (RegionView*)0)); + region->set_start (_trackview.track()->current_capture_start() - _trackview.track()->get_capture_start_frame (0), this); + region->set_position (_trackview.track()->current_capture_start(), this); + RegionView* rv = add_region_view_internal (region, false); + MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (rv); + mrv->begin_write (); + + rec_regions.push_back (make_pair (region, rv)); // rec regions are destroyed in setup_rec_box @@ -470,14 +474,13 @@ MidiStreamView::setup_rec_box () /* start a new rec box */ boost::shared_ptr<MidiTrack> mt = _trackview.midi_track(); /* we know what it is already */ - nframes_t frame_pos = mt->current_capture_start (); - gdouble xstart = _trackview.editor().frame_to_pixel (frame_pos); - gdouble xend; + framepos_t const frame_pos = mt->current_capture_start (); + gdouble const xstart = _trackview.editor().frame_to_pixel (frame_pos); + gdouble const xend = xstart; uint32_t fill_color; assert(_trackview.midi_track()->mode() == Normal); - xend = xstart; fill_color = ARDOUR_UI::config()->canvasvar_RecordingRect.get(); ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*_canvas_group); @@ -552,165 +555,6 @@ MidiStreamView::setup_rec_box () } } -/** @param start Start position to update in session frames */ -void -MidiStreamView::update_rec_regions (boost::shared_ptr<MidiModel> data, framepos_t const start, nframes_t dur) -{ - ENSURE_GUI_THREAD (*this, &MidiStreamView::update_rec_regions, data, start, dur) - - if (Config->get_show_waveforms_while_recording ()) { - - uint32_t n = 0; - bool update_range = false; - - for (list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator iter = rec_regions.begin(); - iter != rec_regions.end(); n++) { - - list<pair<boost::shared_ptr<Region>,RegionView*> >::iterator tmp = iter; - ++tmp; - - if (!canvas_item_visible (rec_rects[n].rectangle)) { - /* rect already hidden, this region is done */ - iter = tmp; - continue; - } - - boost::shared_ptr<MidiRegion> region = boost::dynamic_pointer_cast<MidiRegion>(iter->first); - if (!region) { - iter = tmp; - continue; - } - - nframes_t origlen = region->length(); - - if (region == rec_regions.back().first && rec_active) { - - if (start >= region->midi_source(0)->timeline_position()) { - - nframes_t nlen = start + dur - region->position(); - - if (nlen != region->length()) { - - region->suspend_property_changes (); - region->set_position (_trackview.track()->get_capture_start_frame(n), this); - region->set_length (start + dur - region->position(), this); - region->resume_property_changes (); - - if (origlen == 1) { - /* our special initial length */ - iter->second = add_region_view_internal (region, false); - ((MidiRegionView*)iter->second)->begin_write(); - } - - ARDOUR::BeatsFramesConverter tconv(_trackview.session()->tempo_map(), region->position() - region->start()); - const MidiModel::TimeType start_beats = tconv.from (start - tconv.origin_b ()); - - /* draw events */ - MidiRegionView* mrv = (MidiRegionView*)iter->second; - - for (MidiModel::Notes::const_iterator i = data->note_lower_bound(start_beats); - i != data->notes().end(); ++i) { - - const boost::shared_ptr<MidiRegionView::NoteType>& note = *i; - - cerr << "New note arrived, length = " << note->length() - << " num " << note->note() - << endl; - - if (note->length() == 0) { - /* we got NoteOn but not NoteOff (yet) - */ - continue; - } - - nframes_t note_start_frames = tconv.to(note->time()); - nframes_t note_end_frames = tconv.to(note->end_time()); - - - if (note->length() > 0 && note_end_frames + region->position() > start) { - mrv->resolve_note(note->note(), note_end_frames); - } - - if (note_start_frames + region->position() < start) { - continue; - } - - if (note_start_frames + region->position() > start + dur) { - break; - } - - if (note->note() < _lowest_note) { - _lowest_note = note->note(); - update_range = true; - } else if (note->note() > _highest_note) { - _highest_note = note->note(); - update_range = true; - } - - mrv->add_note (note, !update_range); - } - - mrv->extend_active_notes(); - } - } - - } else { - - nframes_t nlen = _trackview.track()->get_captured_frames(n); - - if (nlen != region->length()) { - - if (region->source_length(0) >= region->position() + nlen) { - - region->suspend_property_changes (); - region->set_position (_trackview.track()->get_capture_start_frame(n), this); - region->set_length (nlen, this); - region->resume_property_changes (); - - if (origlen == 1) { - /* our special initial length */ - iter->second = add_region_view_internal (region, false); - } - - /* also hide rect */ - ArdourCanvas::Item * rect = rec_rects[n].rectangle; - rect->hide(); - - } - } - } - - iter = tmp; - } - - if (update_range) - update_contents_height(); - } -} - -/** @param start Start of the range in session frames. - * @param cnd Number of frames in the range. - */ -void -MidiStreamView::rec_data_range_ready (framepos_t start, nframes_t cnt, boost::weak_ptr<Source> weak_src) -{ - // this is called from the butler thread for now - - ENSURE_GUI_THREAD (*this, &MidiStreamView::rec_data_range_ready, start, cnt, weak_src) - - boost::shared_ptr<SMFSource> src (boost::dynamic_pointer_cast<SMFSource>(weak_src.lock())); - - if (!src) { - return; - } - - if (start + cnt > last_rec_data_frame) { - last_rec_data_frame = start + cnt; - } - - this->update_rec_regions (src->model(), start, cnt); -} - void MidiStreamView::color_handler () { @@ -751,3 +595,19 @@ MidiStreamView::note_range_adjustment_changed() apply_note_range(lowest, highest, true); } +void +MidiStreamView::update_rec_box () +{ + StreamView::update_rec_box (); + + if (rec_regions.empty()) { + return; + } + + /* Update the region being recorded to reflect where we currently are */ + boost::shared_ptr<ARDOUR::Region> region = rec_regions.back().first; + region->set_length (_trackview.track()->current_capture_end () - _trackview.track()->current_capture_start(), this); + + MidiRegionView* mrv = dynamic_cast<MidiRegionView*> (rec_regions.back().second); + mrv->extend_active_notes (); +} diff --git a/gtk2_ardour/midi_streamview.h b/gtk2_ardour/midi_streamview.h index e4fdd57718..b29f030e61 100644 --- a/gtk2_ardour/midi_streamview.h +++ b/gtk2_ardour/midi_streamview.h @@ -98,19 +98,12 @@ class MidiStreamView : public StreamView RegionView* create_region_view (boost::shared_ptr<ARDOUR::Region>, bool, bool); + void apply_note_range(uint8_t lowest, uint8_t highest, bool to_region_views); + private: void setup_rec_box (); + void update_rec_box (); - void rec_data_range_ready ( - ARDOUR::framepos_t start, - nframes_t dur, - boost::weak_ptr<ARDOUR::Source> src); - - void update_rec_regions ( - boost::shared_ptr<ARDOUR::MidiModel> data, - ARDOUR::framepos_t const start, - nframes_t dur); - RegionView* add_region_view_internal ( boost::shared_ptr<ARDOUR::Region>, bool wait_for_waves, @@ -122,7 +115,6 @@ class MidiStreamView : public StreamView void update_contents_height (); void draw_note_lines(); - void apply_note_range(uint8_t lowest, uint8_t highest, bool to_region_views); bool update_data_note_range(uint8_t min, uint8_t max); void update_contents_metrics(boost::shared_ptr<ARDOUR::Region> r); diff --git a/gtk2_ardour/streamview.cc b/gtk2_ardour/streamview.cc index 85974a039c..5201cf295c 100644 --- a/gtk2_ardour/streamview.cc +++ b/gtk2_ardour/streamview.cc @@ -414,7 +414,7 @@ StreamView::update_rec_box () if (rec_active && rec_rects.size() > 0) { /* only update the last box */ RecBoxInfo & rect = rec_rects.back(); - nframes_t at = _trackview.track()->current_capture_end(); + framepos_t const at = _trackview.track()->current_capture_end (); double xstart; double xend; diff --git a/gtk2_ardour/streamview.h b/gtk2_ardour/streamview.h index 5dbe32b2f3..8c2242e587 100644 --- a/gtk2_ardour/streamview.h +++ b/gtk2_ardour/streamview.h @@ -122,7 +122,7 @@ protected: void rec_enable_changed(); void sess_rec_enable_changed(); virtual void setup_rec_box () = 0; - void update_rec_box (); + virtual void update_rec_box (); virtual RegionView* add_region_view_internal (boost::shared_ptr<ARDOUR::Region>, bool wait_for_waves, bool recording = false) = 0; diff --git a/libs/ardour/ardour/diskstream.h b/libs/ardour/ardour/diskstream.h index 4baf2668a6..4eabe29d85 100644 --- a/libs/ardour/ardour/diskstream.h +++ b/libs/ardour/ardour/diskstream.h @@ -110,11 +110,11 @@ class Diskstream : public SessionObject, public PublicDiskstream virtual int use_new_playlist () = 0; virtual int use_copy_playlist () = 0; - /** @return Capture start position in session frames */ + /** @return Start position of currently-running capture (in session frames) */ framepos_t current_capture_start() const { return capture_start_frame; } framepos_t current_capture_end() const { return capture_start_frame + capture_captured; } - framepos_t get_capture_start_frame (uint32_t n=0); - framecnt_t get_captured_frames (uint32_t n=0); + framepos_t get_capture_start_frame (uint32_t n = 0) const; + framecnt_t get_captured_frames (uint32_t n = 0) const; ChanCount n_channels() { return _n_channels; } @@ -242,8 +242,8 @@ class Diskstream : public SessionObject, public PublicDiskstream nframes_t& rec_nframes, nframes_t& rec_offset); static nframes_t disk_io_chunk_frames; - std::vector<CaptureInfo*> capture_info; - Glib::Mutex capture_info_lock; + std::vector<CaptureInfo*> capture_info; + mutable Glib::Mutex capture_info_lock; uint32_t i_am_the_modifier; @@ -261,7 +261,8 @@ class Diskstream : public SessionObject, public PublicDiskstream bool _seek_required; bool force_refill; - framepos_t capture_start_frame; ///< session frames + /** Start of currently running capture in session frames */ + framepos_t capture_start_frame; framecnt_t capture_captured; bool was_recording; nframes_t adjust_capture_position; diff --git a/libs/ardour/ardour/midi_diskstream.h b/libs/ardour/ardour/midi_diskstream.h index 49a7525dc7..126857a858 100644 --- a/libs/ardour/ardour/midi_diskstream.h +++ b/libs/ardour/ardour/midi_diskstream.h @@ -107,6 +107,12 @@ class MidiDiskstream : public Diskstream return playback_mode; } + /** Emitted when some MIDI data has been received for recording. + * First parameter is the data. + * Second parameter is the source that it is destined for. + */ + PBD::Signal2<void, boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource> > DataRecorded; + protected: friend class Session; friend class Butler; diff --git a/libs/ardour/ardour/midi_source.h b/libs/ardour/ardour/midi_source.h index 221bfd13f0..0c2759b96d 100644 --- a/libs/ardour/ardour/midi_source.h +++ b/libs/ardour/ardour/midi_source.h @@ -91,12 +91,6 @@ class MidiSource : virtual public Source static PBD::Signal1<void,MidiSource*> MidiSourceCreated; - /** Emitted when a range of recorded data is available for reading from model(). - * First parameter is the start of the range in session frames. - * Second parameter is the number of frames. - */ - mutable PBD::Signal2<void,framepos_t,nframes_t> ViewDataRangeReady; - XMLNode& get_state (); int set_state (const XMLNode&, int version); diff --git a/libs/ardour/ardour/midi_track.h b/libs/ardour/ardour/midi_track.h index 0475f3f5ea..91ccc4b1fe 100644 --- a/libs/ardour/ardour/midi_track.h +++ b/libs/ardour/ardour/midi_track.h @@ -102,6 +102,8 @@ public: uint16_t get_channel_mask (); boost::shared_ptr<MidiPlaylist> midi_playlist (); + PBD::Signal2<void, boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource> > DataRecorded; + protected: XMLNode& state (bool full); @@ -125,6 +127,9 @@ private: int no_roll (nframes_t nframes, framepos_t start_frame, framepos_t end_frame, bool state_changing, bool can_record, bool rec_monitors_input); void push_midi_input_to_step_edit_ringbuffer (nframes_t nframes); + + void diskstream_data_recorded (boost::shared_ptr<MidiBuffer>, boost::weak_ptr<MidiSource>); + PBD::ScopedConnection _diskstream_data_recorded_connection; }; } /* namespace ARDOUR*/ diff --git a/libs/ardour/ardour/public_diskstream.h b/libs/ardour/ardour/public_diskstream.h index de6b3dcb55..41aaeb44ee 100755 --- a/libs/ardour/ardour/public_diskstream.h +++ b/libs/ardour/ardour/public_diskstream.h @@ -54,7 +54,7 @@ public: virtual void non_realtime_locate (framepos_t) = 0; virtual void non_realtime_set_speed () = 0; virtual int overwrite_existing_buffers () = 0; - virtual framecnt_t get_captured_frames (uint32_t n = 0) = 0; + virtual framecnt_t get_captured_frames (uint32_t n = 0) const = 0; virtual int set_loop (Location *) = 0; virtual void transport_looped (framepos_t) = 0; virtual bool realtime_set_speed (double, bool) = 0; @@ -64,7 +64,7 @@ public: virtual void prepare_to_stop (framepos_t) = 0; virtual void set_slaved (bool) = 0; virtual ChanCount n_channels () = 0; - virtual framepos_t get_capture_start_frame (uint32_t n = 0) = 0; + virtual framepos_t get_capture_start_frame (uint32_t n = 0) const = 0; virtual AlignStyle alignment_style () const = 0; virtual framepos_t current_capture_start () const = 0; virtual framepos_t current_capture_end () const = 0; diff --git a/libs/ardour/ardour/track.h b/libs/ardour/ardour/track.h index 38d36ea5d0..ff1b57950a 100644 --- a/libs/ardour/ardour/track.h +++ b/libs/ardour/ardour/track.h @@ -122,7 +122,7 @@ class Track : public Route, public PublicDiskstream void non_realtime_locate (framepos_t); void non_realtime_set_speed (); int overwrite_existing_buffers (); - framecnt_t get_captured_frames (uint32_t n = 0); + framecnt_t get_captured_frames (uint32_t n = 0) const; int set_loop (Location *); void transport_looped (framepos_t); bool realtime_set_speed (double, bool); @@ -132,7 +132,7 @@ class Track : public Route, public PublicDiskstream void prepare_to_stop (framepos_t); void set_slaved (bool); ChanCount n_channels (); - framepos_t get_capture_start_frame (uint32_t n = 0); + framepos_t get_capture_start_frame (uint32_t n = 0) const; AlignStyle alignment_style () const; framepos_t current_capture_start () const; framepos_t current_capture_end () const; diff --git a/libs/ardour/diskstream.cc b/libs/ardour/diskstream.cc index 2c1877b7b5..908e1db5c8 100644 --- a/libs/ardour/diskstream.cc +++ b/libs/ardour/diskstream.cc @@ -293,32 +293,35 @@ Diskstream::set_loop (Location *location) loop_location = location; - LoopSet (location); /* EMIT SIGNAL */ + LoopSet (location); /* EMIT SIGNAL */ return 0; } +/** Get the start position (in session frames) of the nth capture in the current pass */ ARDOUR::framepos_t -Diskstream::get_capture_start_frame (uint32_t n) +Diskstream::get_capture_start_frame (uint32_t n) const { Glib::Mutex::Lock lm (capture_info_lock); if (capture_info.size() > n) { + /* this is a completed capture */ return capture_info[n]->start; - } - else { + } else { + /* this is the currently in-progress capture */ return capture_start_frame; } } ARDOUR::framecnt_t -Diskstream::get_captured_frames (uint32_t n) +Diskstream::get_captured_frames (uint32_t n) const { Glib::Mutex::Lock lm (capture_info_lock); if (capture_info.size() > n) { + /* this is a completed capture */ return capture_info[n]->frames; - } - else { + } else { + /* this is the currently in-progress capture */ return capture_captured; } } diff --git a/libs/ardour/midi_diskstream.cc b/libs/ardour/midi_diskstream.cc index 0ac67fae82..f5b9cb5345 100644 --- a/libs/ardour/midi_diskstream.cc +++ b/libs/ardour/midi_diskstream.cc @@ -540,6 +540,16 @@ MidiDiskstream::process (framepos_t transport_frame, nframes_t nframes, bool can _capture_buf->write(ev.time() + transport_frame, ev.type(), ev.size(), ev.buffer()); } + if (buf.size() != 0) { + /* Make a copy of this data and emit it for the GUI to see */ + boost::shared_ptr<MidiBuffer> copy (new MidiBuffer (buf.capacity ())); + for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) { + copy->push_back ((*i).time() + transport_frame, (*i).size(), (*i).buffer()); + } + + DataRecorded (copy, _write_source); /* EMIT SIGNAL */ + } + } else { if (was_recording) { @@ -837,8 +847,7 @@ MidiDiskstream::do_flush (RunContext /*context*/, bool force_flush) total = _session.transport_frame() - _last_flush_frame; - if (_last_flush_frame > _session.transport_frame() - || _last_flush_frame < capture_start_frame) { + if (_last_flush_frame > _session.transport_frame() || _last_flush_frame < capture_start_frame) { _last_flush_frame = _session.transport_frame(); } @@ -869,7 +878,7 @@ MidiDiskstream::do_flush (RunContext /*context*/, bool force_flush) if (record_enabled() && ((_session.transport_frame() - _last_flush_frame > disk_io_chunk_frames) || force_flush)) { - if ((!_write_source) || _write_source->midi_write (*_capture_buf, capture_start_frame, to_write) != to_write) { + if ((!_write_source) || _write_source->midi_write (*_capture_buf, get_capture_start_frame (0), to_write) != to_write) { error << string_compose(_("MidiDiskstream %1: cannot write to disk"), _id) << endmsg; return -1; } else { @@ -1002,8 +1011,13 @@ MidiDiskstream::transport_stopped_wallclock (struct tm& /*when*/, time_t /*twhen _playlist->clear_changes (); _playlist->freeze (); - uint32_t buffer_position = 0; - for (buffer_position = 0, ci = capture_info.begin(); ci != capture_info.end(); ++ci) { + /* Session frame time of the initial capture in this pass, which is where the source starts */ + framepos_t initial_capture = 0; + if (!capture_info.empty()) { + initial_capture = capture_info.front()->start; + } + + for (ci = capture_info.begin(); ci != capture_info.end(); ++ci) { string region_name; @@ -1013,8 +1027,9 @@ MidiDiskstream::transport_stopped_wallclock (struct tm& /*when*/, time_t /*twhen try { PropertyList plist; - - plist.add (Properties::start, buffer_position); + + /* start of this region is the offset between the start of its capture and the start of the whole pass */ + plist.add (Properties::start, (*ci)->start - initial_capture); plist.add (Properties::length, (*ci)->frames); plist.add (Properties::name, region_name); @@ -1032,8 +1047,6 @@ MidiDiskstream::transport_stopped_wallclock (struct tm& /*when*/, time_t /*twhen i_am_the_modifier++; _playlist->add_region (region, (*ci)->start); i_am_the_modifier--; - - buffer_position += (*ci)->frames; } _playlist->thaw (); @@ -1151,8 +1164,6 @@ MidiDiskstream::engage_record_enable () _source_port->request_monitor_input (!(_session.config.get_auto_input() && rolling)); } - _write_source->mark_streaming_midi_write_started (_note_mode, _session.transport_frame()); - RecordEnableChanged (); /* EMIT SIGNAL */ } diff --git a/libs/ardour/midi_track.cc b/libs/ardour/midi_track.cc index 595fccf360..452e3038bd 100644 --- a/libs/ardour/midi_track.cc +++ b/libs/ardour/midi_track.cc @@ -105,6 +105,10 @@ MidiTrack::set_diskstream (boost::shared_ptr<Diskstream> ds) _diskstream->set_record_enabled (false); //_diskstream->monitor_input (false); + _diskstream_data_recorded_connection.disconnect (); + boost::shared_ptr<MidiDiskstream> mds = boost::dynamic_pointer_cast<MidiDiskstream> (ds); + mds->DataRecorded.connect_same_thread (_diskstream_data_recorded_connection, boost::bind (&MidiTrack::diskstream_data_recorded, this, _1, _2)); + DiskstreamChanged (); /* EMIT SIGNAL */ } @@ -633,3 +637,10 @@ MidiTrack::midi_playlist () { return midi_diskstream()->midi_playlist (); } + +void +MidiTrack::diskstream_data_recorded (boost::shared_ptr<MidiBuffer> buf, boost::weak_ptr<MidiSource> src) +{ + DataRecorded (buf, src); /* EMIT SIGNAL */ +} + diff --git a/libs/ardour/smf_source.cc b/libs/ardour/smf_source.cc index 322c4dff97..1b9be5ddaa 100644 --- a/libs/ardour/smf_source.cc +++ b/libs/ardour/smf_source.cc @@ -266,8 +266,6 @@ SMFSource::write_unlocked (MidiRingBuffer<nframes_t>& source, framepos_t positio Evoral::SMF::flush(); free(buf); - ViewDataRangeReady (_last_write_end, duration); /* EMIT SIGNAL */ - return duration; } diff --git a/libs/ardour/track.cc b/libs/ardour/track.cc index 46517e1752..72fcac8c46 100644 --- a/libs/ardour/track.cc +++ b/libs/ardour/track.cc @@ -528,7 +528,7 @@ Track::overwrite_existing_buffers () } framecnt_t -Track::get_captured_frames (uint32_t n) +Track::get_captured_frames (uint32_t n) const { return _diskstream->get_captured_frames (n); } @@ -588,7 +588,7 @@ Track::n_channels () } framepos_t -Track::get_capture_start_frame (uint32_t n) +Track::get_capture_start_frame (uint32_t n) const { return _diskstream->get_capture_start_frame (n); } |