2005-09-25 14:42:24 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2003 Paul Davis
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
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 <algorithm>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/region.h"
|
2005-09-25 16:33:00 -04:00
|
|
|
#include <gtkmm2ext/doi.h>
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
#include "canvas-simplerect.h"
|
|
|
|
#include "canvas-curve.h"
|
|
|
|
#include "crossfade_view.h"
|
2010-12-02 10:51:42 -05:00
|
|
|
#include "global_signals.h"
|
2009-12-21 13:23:07 -05:00
|
|
|
#include "gui_thread.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "rgb_macros.h"
|
|
|
|
#include "audio_time_axis.h"
|
|
|
|
#include "public_editor.h"
|
2006-08-01 13:19:38 -04:00
|
|
|
#include "audio_region_view.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
#include "utils.h"
|
2005-12-29 19:34:21 -05:00
|
|
|
#include "canvas_impl.h"
|
2007-06-29 13:13:09 -04:00
|
|
|
#include "ardour_ui.h"
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
using namespace ARDOUR;
|
Large nasty commit in the form of a 5000 line patch chock-full of completely
unecessary changes. (Sorry, doing a "sprint" based thing, this is the end of the first one)
Achieved MIDI track and bus creation, associated Jack port and diskstream creation, and minimal GUI stuff for creating them. Should be set to start work on actually recording and playing midi to/from disk now.
Relevant (significant) changes:
- Creation of a Buffer class. Base class is type agnostic so things can point to a buffer but not care what kind it is (otherwise it'd be a template). Derived into AudioBuffer and MidiBuffer, with a type tag because checking type is necessary in parts of the code where dynamic_cast wouldn't be wise. Originally I considered this a hack, but passing around a type proved to be a very good solution to all the other problems (below). There is a 1:1 mapping between jack port data types and ardour Buffer types (with a conversion function), but that's easily removed if it ever becomes necessary. Having the type scoped in the Buffer class is maybe not the best spot for it, but whatever (this is proof of concept kinda stuff right now...)
- IO now has a "default" port type (passed to the constructor and stored as a member), used by ensure_io (and similar) to create n ports. IO::register_***_port has a type argument that defaults to the default type if not passed. Rationale: previous IO API is identical, no changes needed to existing code, but path is paved for multiple port types in one IO, which we will need for eg synth plugin inserts, among other things. This is not quite ideal (best would be to only have the two port register functions and have them take a type), but the alternative is a lot of work (namely destroying the 'ensure' functions and everything that uses them) for very little gain. (I am convinced after quite a few tries at the whiteboard that subclassing IO in any way is not a feasible option, look at it's inheritance diagram in Doxygen and you can see why)
- AudioEngine::register_audio_input_port is now register_input_port and takes a type argument. Ditto for output.
- (Most significant change) AudioDiskstream abstracted into Distream, and sibling MidiDiskstream created. Very much still a work in progress, but Diskstream is there to switch references over to (most already are), which is the important part. It is still unclear what the MIDI diskstream's relation to channels is, but I'm pretty sure they will be single channel only (so SMF Type 0) since noone can come up with a reason otherwise.
- MidiTrack creation. Same thing as AudioTrack but with a different default type basically. No big deal here.
- Random cleanups and variable renamings etc. because I have OCD and can't help myself. :)
Known broken: Loading of sessions containing MIDI tracks.
git-svn-id: svn://localhost/ardour2/branches/midi@641 d708f5d6-7413-0410-9779-e7cbd77b26cf
2006-06-26 12:01:34 -04:00
|
|
|
using namespace PBD;
|
2005-09-25 14:42:24 -04:00
|
|
|
using namespace Editing;
|
2005-11-22 00:10:12 -05:00
|
|
|
using namespace Gnome;
|
|
|
|
using namespace Canvas;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-12-22 15:21:43 -05:00
|
|
|
PBD::Signal1<void,CrossfadeView*> CrossfadeView::CatchDeletion;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
CrossfadeView::CrossfadeView (ArdourCanvas::Group *parent,
|
|
|
|
RouteTimeAxisView &tv,
|
|
|
|
boost::shared_ptr<Crossfade> xf,
|
2005-09-25 14:42:24 -04:00
|
|
|
double spu,
|
2005-10-06 00:59:20 -04:00
|
|
|
Gdk::Color& basic_color,
|
2005-09-25 14:42:24 -04:00
|
|
|
AudioRegionView& lview,
|
|
|
|
AudioRegionView& rview)
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
|
|
|
|
: TimeAxisViewItem ("xfade" /*xf.name()*/, *parent, tv, spu, basic_color, xf->position(),
|
2010-09-02 15:09:46 -04:00
|
|
|
xf->length(), false, false, TimeAxisViewItem::Visibility (TimeAxisViewItem::ShowFrame)),
|
2005-09-25 14:42:24 -04:00
|
|
|
crossfade (xf),
|
|
|
|
left_view (lview),
|
2010-10-17 19:35:05 -04:00
|
|
|
right_view (rview),
|
|
|
|
_all_in_view (false)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
_valid = true;
|
|
|
|
_visible = true;
|
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in = new Line (*group);
|
2007-06-29 13:13:09 -04:00
|
|
|
fade_in->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CrossfadeLine.get();
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_in->property_width_pixels() = 1;
|
2005-11-22 00:10:12 -05:00
|
|
|
|
|
|
|
fade_out = new Line (*group);
|
2007-06-29 13:13:09 -04:00
|
|
|
fade_out->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_CrossfadeLine.get();
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_out->property_width_pixels() = 1;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
/* no frame around the xfade or overlap rects */
|
|
|
|
|
2005-11-27 17:35:04 -05:00
|
|
|
frame->property_outline_what() = 0;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* never show the vestigial frame */
|
2005-11-12 22:53:51 -05:00
|
|
|
vestigial_frame->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
show_vestigial = false;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2009-12-11 18:29:48 -05:00
|
|
|
group->signal_event().connect (sigc::bind (sigc::mem_fun (tv.editor(), &PublicEditor::canvas_crossfade_view_event), group, this));
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-02-19 13:09:08 -05:00
|
|
|
PropertyChange all_crossfade_properties;
|
|
|
|
all_crossfade_properties.add (ARDOUR::Properties::active);
|
|
|
|
all_crossfade_properties.add (ARDOUR::Properties::follow_overlap);
|
|
|
|
crossfade_changed (all_crossfade_properties);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-03-30 11:18:43 -04:00
|
|
|
crossfade->PropertyChanged.connect (*this, invalidator (*this), ui_bind (&CrossfadeView::crossfade_changed, this, _1), gui_context());
|
2010-06-27 22:40:09 -04:00
|
|
|
crossfade->FadesChanged.connect (*this, invalidator (*this), ui_bind (&CrossfadeView::crossfade_fades_changed, this), gui_context());
|
2009-12-11 18:29:48 -05:00
|
|
|
ColorsChanged.connect (sigc::mem_fun (*this, &CrossfadeView::color_handler));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
CrossfadeView::~CrossfadeView ()
|
|
|
|
{
|
2009-12-22 15:21:43 -05:00
|
|
|
CatchDeletion (this) ; /* EMIT_SIGNAL */
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::reset_width_dependent_items (double pixel_width)
|
|
|
|
{
|
|
|
|
TimeAxisViewItem::reset_width_dependent_items (pixel_width);
|
|
|
|
|
|
|
|
active_changed ();
|
|
|
|
|
|
|
|
if (pixel_width < 5) {
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in->hide();
|
|
|
|
fade_out->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-06 21:11:31 -04:00
|
|
|
CrossfadeView::set_height (double h)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
2010-06-05 20:55:53 -04:00
|
|
|
if (h > TimeAxisView::preset_height (HeightSmall)) {
|
|
|
|
h -= NAME_HIGHLIGHT_SIZE;
|
2007-05-17 06:41:14 -04:00
|
|
|
}
|
|
|
|
|
2009-08-25 21:49:08 -04:00
|
|
|
TimeAxisViewItem::set_height (h);
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
redraw_curves ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-02-19 13:09:08 -05:00
|
|
|
CrossfadeView::crossfade_changed (const PropertyChange& what_changed)
|
2005-09-25 14:42:24 -04:00
|
|
|
{
|
|
|
|
bool need_redraw_curves = false;
|
|
|
|
|
2010-02-19 13:09:08 -05:00
|
|
|
if (what_changed.contains (ARDOUR::bounds_change)) {
|
2007-01-11 14:50:49 -05:00
|
|
|
set_position (crossfade->position(), this);
|
|
|
|
set_duration (crossfade->length(), this);
|
2009-08-23 15:42:01 -04:00
|
|
|
|
|
|
|
/* set_duration will call reset_width_dependent_items which in turn will call redraw_curves via active_changed,
|
|
|
|
so no need for us to call it */
|
|
|
|
need_redraw_curves = false;
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2006-10-21 18:59:29 -04:00
|
|
|
|
2010-02-19 13:09:08 -05:00
|
|
|
if (what_changed.contains (ARDOUR::Properties::follow_overlap)) {
|
2006-10-21 18:59:29 -04:00
|
|
|
need_redraw_curves = true;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2010-02-19 13:09:08 -05:00
|
|
|
if (what_changed.contains (ARDOUR::Properties::active)) {
|
2005-09-25 14:42:24 -04:00
|
|
|
/* calls redraw_curves */
|
|
|
|
active_changed ();
|
|
|
|
} else if (need_redraw_curves) {
|
|
|
|
redraw_curves ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-17 19:35:05 -04:00
|
|
|
/** Set up our fade_in and fade_out curves to contain points for the currently visible portion
|
|
|
|
* of the crossfade.
|
|
|
|
*/
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
|
|
|
CrossfadeView::redraw_curves ()
|
|
|
|
{
|
2007-01-11 14:50:49 -05:00
|
|
|
if (!crossfade->following_overlap()) {
|
2006-10-21 18:59:29 -04:00
|
|
|
/* curves should not be visible */
|
|
|
|
fade_in->hide ();
|
|
|
|
fade_out->hide ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-08-25 21:49:08 -04:00
|
|
|
if (_height < 0) {
|
2005-09-25 14:42:24 -04:00
|
|
|
/* no space allocated yet */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-10-17 19:35:05 -04:00
|
|
|
PublicEditor& editor = get_time_axis_view().editor ();
|
|
|
|
|
|
|
|
framepos_t const editor_left = editor.leftmost_position ();
|
|
|
|
framepos_t const editor_right = editor_left + editor.current_page_frames ();
|
|
|
|
framepos_t const xfade_left = crossfade->position ();
|
|
|
|
framepos_t const xfade_right = xfade_left + crossfade->length ();
|
|
|
|
|
|
|
|
/* Work out the range of our frames that are visible */
|
|
|
|
framepos_t const min_frames = std::max (editor_left, xfade_left);
|
|
|
|
framepos_t const max_frames = std::min (editor_right, xfade_right);
|
|
|
|
|
|
|
|
_all_in_view = (editor_left <= xfade_left && editor_right >= xfade_right);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-10-17 19:35:05 -04:00
|
|
|
/* Hence the number of points that we will render */
|
|
|
|
int32_t const npoints = editor.frame_to_pixel (max_frames - min_frames);
|
|
|
|
|
2007-01-11 14:50:49 -05:00
|
|
|
if (!_visible || !crossfade->active() || npoints < 3) {
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in->hide();
|
|
|
|
fade_out->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
return;
|
|
|
|
} else {
|
2005-11-22 00:10:12 -05:00
|
|
|
fade_in->show();
|
|
|
|
fade_out->show();
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-10-17 19:35:05 -04:00
|
|
|
Points* points = get_canvas_points ("xfade edit redraw", npoints);
|
|
|
|
float* vec = new float[npoints];
|
|
|
|
|
|
|
|
crossfade->fade_in().curve().get_vector (min_frames - crossfade->position(), max_frames - crossfade->position(), vec, npoints);
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-10-17 19:35:05 -04:00
|
|
|
/* Work out the offset from the start of the crossfade to the visible part, in pixels */
|
|
|
|
double xoff = 0;
|
|
|
|
if (crossfade->position() < editor.leftmost_position()) {
|
|
|
|
xoff = editor.frame_to_pixel (min_frames) - editor.frame_to_pixel (crossfade->position ());
|
|
|
|
}
|
2008-12-12 09:43:24 -05:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
for (int i = 0, pci = 0; i < npoints; ++i) {
|
2005-11-22 00:10:12 -05:00
|
|
|
Art::Point &p = (*points)[pci++];
|
2010-10-17 19:35:05 -04:00
|
|
|
p.set_x (xoff + i + 1);
|
2010-06-05 20:55:53 -04:00
|
|
|
p.set_y (_height - ((_height - 2) * vec[i]));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2010-09-08 21:38:02 -04:00
|
|
|
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_in->property_points() = *points;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
2010-10-17 19:35:05 -04:00
|
|
|
crossfade->fade_out().curve().get_vector (min_frames - crossfade->position(), max_frames - crossfade->position(), vec, npoints);
|
2010-04-03 18:35:44 -04:00
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
for (int i = 0, pci = 0; i < npoints; ++i) {
|
2005-11-22 00:10:12 -05:00
|
|
|
Art::Point &p = (*points)[pci++];
|
2010-10-17 19:35:05 -04:00
|
|
|
p.set_x (xoff + i + 1);
|
2010-06-05 20:55:53 -04:00
|
|
|
p.set_y (_height - ((_height - 2) * vec[i]));
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2010-04-03 18:35:44 -04:00
|
|
|
|
2005-11-27 15:07:16 -05:00
|
|
|
fade_out->property_points() = *points;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
delete [] vec;
|
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
delete points;
|
2005-09-25 14:42:24 -04:00
|
|
|
|
|
|
|
/* XXX this is ugly, but it will have to wait till Crossfades are reimplented
|
|
|
|
as regions. This puts crossfade views on top of a track, above all regions.
|
|
|
|
*/
|
|
|
|
|
2005-11-12 22:53:51 -05:00
|
|
|
group->raise_to_top();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::active_changed ()
|
|
|
|
{
|
2007-01-11 14:50:49 -05:00
|
|
|
if (crossfade->active()) {
|
2007-06-29 13:13:09 -04:00
|
|
|
frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_ActiveCrossfade.get();
|
2005-09-25 14:42:24 -04:00
|
|
|
} else {
|
2007-06-29 13:13:09 -04:00
|
|
|
frame->property_fill_color_rgba() = ARDOUR_UI::config()->canvasvar_InactiveCrossfade.get();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
redraw_curves ();
|
|
|
|
}
|
|
|
|
|
2007-06-15 18:08:27 -04:00
|
|
|
void
|
|
|
|
CrossfadeView::color_handler ()
|
|
|
|
{
|
|
|
|
active_changed ();
|
|
|
|
}
|
|
|
|
|
2005-09-25 14:42:24 -04:00
|
|
|
void
|
|
|
|
CrossfadeView::set_valid (bool yn)
|
|
|
|
{
|
|
|
|
_valid = yn;
|
|
|
|
}
|
|
|
|
|
|
|
|
AudioRegionView&
|
|
|
|
CrossfadeView::upper_regionview () const
|
|
|
|
{
|
2006-08-29 17:21:48 -04:00
|
|
|
if (left_view.region()->layer() > right_view.region()->layer()) {
|
2005-09-25 14:42:24 -04:00
|
|
|
return left_view;
|
|
|
|
} else {
|
|
|
|
return right_view;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::show ()
|
|
|
|
{
|
|
|
|
_visible = true;
|
2010-09-08 21:38:02 -04:00
|
|
|
group->show();
|
|
|
|
redraw_curves ();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::hide ()
|
|
|
|
{
|
2005-11-12 22:53:51 -05:00
|
|
|
group->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
_visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::fake_hide ()
|
|
|
|
{
|
2005-11-12 22:53:51 -05:00
|
|
|
group->hide();
|
2005-09-25 14:42:24 -04:00
|
|
|
}
|
2010-06-27 22:40:09 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::crossfade_fades_changed ()
|
|
|
|
{
|
|
|
|
redraw_curves ();
|
|
|
|
}
|
2010-10-17 19:35:05 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
CrossfadeView::horizontal_position_changed ()
|
|
|
|
{
|
|
|
|
/* If the crossfade curves are entirely within the editor's visible space, there is
|
|
|
|
no need to redraw them here as they will be completely drawn (as distinct from
|
|
|
|
the other case where the horizontal position change will uncover `undrawn'
|
|
|
|
sections).
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!_all_in_view) {
|
|
|
|
redraw_curves ();
|
|
|
|
}
|
|
|
|
}
|