2006-07-23 08:03:19 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2001, 2006 Paul Davis
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include <gtkmm.h>
|
|
|
|
|
|
|
|
#include <gtkmm2ext/gtk_ui.h>
|
|
|
|
|
|
|
|
#include <ardour/midi_playlist.h>
|
|
|
|
#include <ardour/midi_region.h>
|
|
|
|
#include <ardour/midi_source.h>
|
|
|
|
#include <ardour/midi_diskstream.h>
|
|
|
|
#include <ardour/midi_track.h>
|
2006-08-29 17:21:48 -04:00
|
|
|
#include <ardour/smf_source.h>
|
|
|
|
#include <ardour/region_factory.h>
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
#include "midi_streamview.h"
|
2006-08-01 13:19:38 -04:00
|
|
|
#include "region_view.h"
|
2006-08-14 04:44:14 -04:00
|
|
|
#include "midi_region_view.h"
|
2006-07-23 08:03:19 -04:00
|
|
|
#include "midi_time_axis.h"
|
|
|
|
#include "canvas-simplerect.h"
|
|
|
|
#include "region_selection.h"
|
|
|
|
#include "selection.h"
|
|
|
|
#include "public_editor.h"
|
|
|
|
#include "ardour_ui.h"
|
|
|
|
#include "rgb_macros.h"
|
|
|
|
#include "gui_thread.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "color.h"
|
|
|
|
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
using namespace Editing;
|
|
|
|
|
|
|
|
MidiStreamView::MidiStreamView (MidiTimeAxisView& tv)
|
|
|
|
: StreamView (tv)
|
|
|
|
{
|
2006-08-14 04:44:14 -04:00
|
|
|
if (tv.is_track())
|
2006-07-23 08:03:19 -04:00
|
|
|
stream_base_color = color_map[cMidiTrackBase];
|
|
|
|
else
|
|
|
|
stream_base_color = color_map[cMidiBusBase];
|
2006-08-14 04:44:14 -04:00
|
|
|
|
2006-07-23 08:03:19 -04:00
|
|
|
canvas_rect->property_fill_color_rgba() = stream_base_color;
|
2006-08-14 04:44:14 -04:00
|
|
|
canvas_rect->property_outline_color_rgba() = color_map[cAudioTrackOutline];
|
2006-07-23 08:03:19 -04:00
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
//use_rec_regions = tv.editor.show_waveforms_recording ();
|
|
|
|
use_rec_regions = true;
|
2006-07-23 08:03:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MidiStreamView::~MidiStreamView ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2006-08-29 17:21:48 -04:00
|
|
|
MidiStreamView::add_region_view_internal (boost::shared_ptr<Region> r, bool wait_for_waves)
|
2006-07-23 08:03:19 -04:00
|
|
|
{
|
|
|
|
ENSURE_GUI_THREAD (bind (mem_fun (*this, &MidiStreamView::add_region_view), r));
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
boost::shared_ptr<MidiRegion> region = boost::dynamic_pointer_cast<MidiRegion> (r);
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
if (region == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MidiRegionView *region_view;
|
|
|
|
list<RegionView *>::iterator i;
|
|
|
|
|
|
|
|
for (i = region_views.begin(); i != region_views.end(); ++i) {
|
2006-08-29 17:21:48 -04:00
|
|
|
if ((*i)->region() == r) {
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
/* great. we already have a MidiRegionView for this Region. use it again. */
|
|
|
|
|
|
|
|
(*i)->set_valid (true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
// can't we all just get along?
|
|
|
|
assert(_trackview.midi_track()->mode() != Destructive);
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
region_view = new MidiRegionView (canvas_group, _trackview, region,
|
2006-08-14 04:44:14 -04:00
|
|
|
_samples_per_unit, region_color);
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
region_view->init (region_color, wait_for_waves);
|
|
|
|
region_views.push_front (region_view);
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
/* follow global waveform setting */
|
|
|
|
|
|
|
|
// FIXME
|
|
|
|
//region_view->set_waveform_visible(_trackview.editor.show_waveforms());
|
|
|
|
|
2006-07-23 08:03:19 -04:00
|
|
|
/* catch regionview going away */
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
region->GoingAway.connect (bind (mem_fun (*this, &MidiStreamView::remove_region_view), region));
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
RegionViewAdded (region_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: code duplication with AudioStreamVIew
|
|
|
|
void
|
|
|
|
MidiStreamView::redisplay_diskstream ()
|
|
|
|
{
|
|
|
|
list<RegionView *>::iterator i, tmp;
|
|
|
|
|
|
|
|
for (i = region_views.begin(); i != region_views.end(); ++i) {
|
|
|
|
(*i)->set_valid (false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_trackview.is_midi_track()) {
|
|
|
|
_trackview.get_diskstream()->playlist()->foreach_region (static_cast<StreamView*>(this), &StreamView::add_region_view);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = region_views.begin(); i != region_views.end(); ) {
|
|
|
|
tmp = i;
|
|
|
|
tmp++;
|
|
|
|
|
|
|
|
if (!(*i)->is_valid()) {
|
|
|
|
delete *i;
|
|
|
|
region_views.erase (i);
|
|
|
|
}
|
|
|
|
|
|
|
|
i = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* now fix layering */
|
|
|
|
|
2006-10-21 18:59:29 -04:00
|
|
|
for (RegionViewList::iterator i = region_views.begin(); i != region_views.end(); ++i) {
|
|
|
|
region_layered (*i);
|
|
|
|
}
|
2006-07-23 08:03:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiStreamView::setup_rec_box ()
|
|
|
|
{
|
|
|
|
// cerr << _trackview.name() << " streamview SRB\n";
|
|
|
|
|
|
|
|
if (_trackview.session().transport_rolling()) {
|
|
|
|
|
|
|
|
if (!rec_active &&
|
|
|
|
_trackview.session().record_status() == Session::Recording &&
|
|
|
|
_trackview.get_diskstream()->record_enabled()) {
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
if (use_rec_regions && rec_regions.size() == rec_rects.size()) {
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
/* add a new region, but don't bother if they set use_rec_regions mid-record */
|
|
|
|
|
|
|
|
MidiRegion::SourceList sources;
|
|
|
|
|
2006-08-24 03:37:17 -04:00
|
|
|
// FIXME
|
|
|
|
boost::shared_ptr<MidiDiskstream> mds = boost::dynamic_pointer_cast<MidiDiskstream>(_trackview.get_diskstream());
|
2006-08-14 04:44:14 -04:00
|
|
|
assert(mds);
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
sources.push_back(mds->write_source());
|
2006-08-14 04:44:14 -04:00
|
|
|
|
|
|
|
rec_data_ready_connections.push_back (mds->write_source()->ViewDataRangeReady.connect (bind (mem_fun (*this, &MidiStreamView::rec_data_range_ready), mds->write_source())));
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
// handle multi
|
|
|
|
|
|
|
|
jack_nframes_t start = 0;
|
|
|
|
if (rec_regions.size() > 0) {
|
|
|
|
start = rec_regions.back()->start() + _trackview.get_diskstream()->get_captured_frames(rec_regions.size()-1);
|
|
|
|
}
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
boost::shared_ptr<MidiRegion> region (boost::dynamic_pointer_cast<MidiRegion>
|
|
|
|
(RegionFactory::create (sources, start, 1 , "", 0, (Region::Flag)(Region::DefaultFlags | Region::DoNotSaveState), false)));
|
|
|
|
assert(region);
|
2006-07-23 08:03:19 -04:00
|
|
|
region->set_position (_trackview.session().transport_frame(), this);
|
|
|
|
rec_regions.push_back (region);
|
2006-09-18 23:29:16 -04:00
|
|
|
|
|
|
|
// rec regions are destroyed in setup_rec_box
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
/* we add the region later */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start a new rec box */
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
MidiTrack* mt = _trackview.midi_track(); /* we know what it is already */
|
2006-08-24 03:37:17 -04:00
|
|
|
boost::shared_ptr<MidiDiskstream> ds = mt->midi_diskstream();
|
|
|
|
jack_nframes_t frame_pos = ds->current_capture_start ();
|
2006-07-23 08:03:19 -04:00
|
|
|
gdouble xstart = _trackview.editor.frame_to_pixel (frame_pos);
|
|
|
|
gdouble xend;
|
|
|
|
uint32_t fill_color;
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
assert(_trackview.midi_track()->mode() == Normal);
|
|
|
|
|
|
|
|
xend = xstart;
|
|
|
|
fill_color = color_map[cRecordingRectFill];
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
ArdourCanvas::SimpleRect * rec_rect = new Gnome::Canvas::SimpleRect (*canvas_group);
|
|
|
|
rec_rect->property_x1() = xstart;
|
|
|
|
rec_rect->property_y1() = 1.0;
|
|
|
|
rec_rect->property_x2() = xend;
|
|
|
|
rec_rect->property_y2() = (double) _trackview.height - 1;
|
|
|
|
rec_rect->property_outline_color_rgba() = color_map[cRecordingRectOutline];
|
|
|
|
rec_rect->property_fill_color_rgba() = fill_color;
|
|
|
|
|
|
|
|
RecBoxInfo recbox;
|
|
|
|
recbox.rectangle = rec_rect;
|
|
|
|
recbox.start = _trackview.session().transport_frame();
|
|
|
|
recbox.length = 0;
|
|
|
|
|
|
|
|
rec_rects.push_back (recbox);
|
|
|
|
|
|
|
|
screen_update_connection.disconnect();
|
|
|
|
screen_update_connection = ARDOUR_UI::instance()->SuperRapidScreenUpdate.connect (mem_fun (*this, &MidiStreamView::update_rec_box));
|
|
|
|
rec_updating = true;
|
|
|
|
rec_active = true;
|
|
|
|
|
|
|
|
} else if (rec_active &&
|
|
|
|
(_trackview.session().record_status() != Session::Recording ||
|
|
|
|
!_trackview.get_diskstream()->record_enabled())) {
|
|
|
|
|
|
|
|
screen_update_connection.disconnect();
|
|
|
|
rec_active = false;
|
|
|
|
rec_updating = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2006-08-23 00:30:57 -04:00
|
|
|
// cerr << "\tNOT rolling, rec_rects = " << rec_rects.size() << " rec_regions = " << rec_regions.size() << endl;
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
if (!rec_rects.empty() || !rec_regions.empty()) {
|
|
|
|
|
|
|
|
/* disconnect rapid update */
|
|
|
|
screen_update_connection.disconnect();
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
for (list<sigc::connection>::iterator prc = rec_data_ready_connections.begin(); prc != rec_data_ready_connections.end(); ++prc) {
|
2006-07-23 08:03:19 -04:00
|
|
|
(*prc).disconnect();
|
|
|
|
}
|
2006-08-14 04:44:14 -04:00
|
|
|
rec_data_ready_connections.clear();
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
rec_updating = false;
|
|
|
|
rec_active = false;
|
2006-08-14 04:44:14 -04:00
|
|
|
last_rec_data_frame = 0;
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
/* remove temp regions */
|
2006-09-18 23:29:16 -04:00
|
|
|
|
|
|
|
for (list<boost::shared_ptr<Region> >::iterator iter = rec_regions.begin(); iter != rec_regions.end();) {
|
|
|
|
list<boost::shared_ptr<Region> >::iterator tmp;
|
|
|
|
tmp = iter;
|
|
|
|
++tmp;
|
|
|
|
(*iter)->drop_references ();
|
|
|
|
iter = tmp;
|
|
|
|
}
|
|
|
|
|
2006-07-23 08:03:19 -04:00
|
|
|
rec_regions.clear();
|
|
|
|
|
|
|
|
// cerr << "\tclear " << rec_rects.size() << " rec rects\n";
|
|
|
|
|
|
|
|
/* transport stopped, clear boxes */
|
|
|
|
for (vector<RecBoxInfo>::iterator iter=rec_rects.begin(); iter != rec_rects.end(); ++iter) {
|
|
|
|
RecBoxInfo &rect = (*iter);
|
|
|
|
delete rect.rectangle;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec_rects.clear();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiStreamView::update_rec_regions ()
|
|
|
|
{
|
|
|
|
if (use_rec_regions) {
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
|
2006-07-23 08:03:19 -04:00
|
|
|
uint32_t n = 0;
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
for (list<boost::shared_ptr<Region> >::iterator iter = rec_regions.begin(); iter != rec_regions.end(); n++) {
|
2006-07-23 08:03:19 -04:00
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
list<boost::shared_ptr<Region> >::iterator tmp;
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
tmp = iter;
|
|
|
|
++tmp;
|
|
|
|
|
|
|
|
if (!canvas_item_visible (rec_rects[n].rectangle)) {
|
|
|
|
/* rect already hidden, this region is done */
|
|
|
|
iter = tmp;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
boost::shared_ptr<MidiRegion> region = boost::dynamic_pointer_cast<MidiRegion>(*iter);
|
2006-07-23 08:03:19 -04:00
|
|
|
assert(region);
|
|
|
|
|
|
|
|
jack_nframes_t origlen = region->length();
|
|
|
|
|
|
|
|
if (region == rec_regions.back() && rec_active) {
|
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
if (last_rec_data_frame > region->start()) {
|
2006-07-23 08:03:19 -04:00
|
|
|
|
2006-08-14 04:44:14 -04:00
|
|
|
jack_nframes_t nlen = last_rec_data_frame - region->start();
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
if (nlen != region->length()) {
|
|
|
|
|
|
|
|
region->freeze ();
|
|
|
|
region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
|
|
|
|
region->set_length (nlen, this);
|
|
|
|
region->thaw ("updated");
|
|
|
|
|
|
|
|
if (origlen == 1) {
|
|
|
|
/* our special initial length */
|
|
|
|
add_region_view_internal (region, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* also update rect */
|
|
|
|
ArdourCanvas::SimpleRect * rect = rec_rects[n].rectangle;
|
|
|
|
gdouble xend = _trackview.editor.frame_to_pixel (region->position() + region->length());
|
|
|
|
rect->property_x2() = xend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
jack_nframes_t nlen = _trackview.get_diskstream()->get_captured_frames(n);
|
|
|
|
|
|
|
|
if (nlen != region->length()) {
|
|
|
|
|
2006-08-29 17:21:48 -04:00
|
|
|
if (region->source(0)->length() >= region->start() + nlen) {
|
2006-07-23 08:03:19 -04:00
|
|
|
|
|
|
|
region->freeze ();
|
|
|
|
region->set_position (_trackview.get_diskstream()->get_capture_start_frame(n), this);
|
|
|
|
region->set_length (nlen, this);
|
|
|
|
region->thaw ("updated");
|
|
|
|
|
|
|
|
if (origlen == 1) {
|
|
|
|
/* our special initial length */
|
|
|
|
add_region_view_internal (region, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* also hide rect */
|
|
|
|
ArdourCanvas::Item * rect = rec_rects[n].rectangle;
|
|
|
|
rect->hide();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
iter = tmp;
|
|
|
|
}
|
|
|
|
}
|
2006-08-14 04:44:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-08-29 17:21:48 -04:00
|
|
|
MidiStreamView::rec_data_range_ready (jack_nframes_t start, jack_nframes_t cnt, boost::shared_ptr<Source> src)
|
2006-08-14 04:44:14 -04:00
|
|
|
{
|
|
|
|
// this is called from the butler thread for now
|
2006-08-21 15:12:26 -04:00
|
|
|
// yeah we need a "peak" building thread or something, though there's not really any
|
|
|
|
// work for it to do... whatever. :)
|
2006-08-14 04:44:14 -04:00
|
|
|
|
|
|
|
ENSURE_GUI_THREAD(bind (mem_fun (*this, &MidiStreamView::rec_data_range_ready), start, cnt, src));
|
|
|
|
|
|
|
|
//cerr << "REC DATA: " << start << " --- " << cnt << endl;
|
|
|
|
|
|
|
|
if (rec_data_ready_map.size() == 0 || start+cnt > last_rec_data_frame) {
|
|
|
|
last_rec_data_frame = start + cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
rec_data_ready_map[src] = true;
|
|
|
|
|
2007-05-09 23:50:17 -04:00
|
|
|
if (rec_data_ready_map.size() == _trackview.get_diskstream()->n_channels().n_midi()) {
|
2006-08-14 04:44:14 -04:00
|
|
|
this->update_rec_regions ();
|
|
|
|
rec_data_ready_map.clear();
|
|
|
|
}
|
2006-07-23 08:03:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiStreamView::color_handler (ColorID id, uint32_t val)
|
|
|
|
{
|
|
|
|
switch (id) {
|
|
|
|
case cMidiTrackBase:
|
|
|
|
if (_trackview.is_midi_track()) {
|
|
|
|
canvas_rect->property_fill_color_rgba() = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cMidiBusBase:
|
|
|
|
if (!_trackview.is_midi_track()) {
|
|
|
|
canvas_rect->property_fill_color_rgba() = val;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case cMidiTrackOutline:
|
|
|
|
canvas_rect->property_outline_color_rgba() = val;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|