2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 22:01:25 -04:00
|
|
|
* Copyright (C) 2006-2016 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2007-2019 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2008-2012 Hans Baier <hansfbaier@googlemail.com>
|
|
|
|
* Copyright (C) 2013-2016 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2013-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
|
|
|
|
* Copyright (C) 2015-2018 Ben Loftis <ben@harrisonconsoles.com>
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2014-11-01 13:35:44 -04:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#ifdef COMPILER_MSVC
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
// 'std::isinf()' and 'std::isnan()' are not available in MSVC.
|
|
|
|
#define isinf_local(val) !((bool)_finite((double)val))
|
|
|
|
#define isnan_local(val) (bool)_isnan((double)val)
|
|
|
|
#else
|
|
|
|
#define isinf_local std::isinf
|
|
|
|
#define isnan_local std::isnan
|
|
|
|
#endif
|
2011-03-14 21:16:24 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/enumwriter.h"
|
2016-08-28 04:47:18 -04:00
|
|
|
#include "pbd/types_convert.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "evoral/midi_util.h"
|
|
|
|
|
2017-03-31 11:28:14 -04:00
|
|
|
#include "ardour/amp.h"
|
2021-07-22 20:05:11 -04:00
|
|
|
#ifdef HAVE_BEATBOX
|
2018-08-13 08:57:22 -04:00
|
|
|
#include "ardour/beatbox.h"
|
2021-07-22 20:05:11 -04:00
|
|
|
#endif
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
#include "ardour/buffer_set.h"
|
2010-06-09 09:00:54 -04:00
|
|
|
#include "ardour/debug.h"
|
2009-06-09 16:21:19 -04:00
|
|
|
#include "ardour/delivery.h"
|
2017-03-31 11:28:14 -04:00
|
|
|
#include "ardour/disk_reader.h"
|
|
|
|
#include "ardour/disk_writer.h"
|
2014-12-01 14:28:03 -05:00
|
|
|
#include "ardour/event_type_map.h"
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
#include "ardour/meter.h"
|
|
|
|
#include "ardour/midi_playlist.h"
|
2009-09-25 01:08:23 -04:00
|
|
|
#include "ardour/midi_port.h"
|
2015-03-26 00:47:34 -04:00
|
|
|
#include "ardour/midi_region.h"
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
#include "ardour/midi_track.h"
|
2016-04-08 16:49:47 -04:00
|
|
|
#include "ardour/monitor_control.h"
|
2014-11-01 23:29:10 -04:00
|
|
|
#include "ardour/parameter_types.h"
|
2009-09-03 08:39:50 -04:00
|
|
|
#include "ardour/port.h"
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
#include "ardour/processor.h"
|
2015-05-12 10:12:41 -04:00
|
|
|
#include "ardour/profile.h"
|
2016-01-31 21:47:19 -05:00
|
|
|
#include "ardour/route_group_specialized.h"
|
The great audio processing overhaul.
The vast majority of Route signal processing is now simply in the list of
processors. There are definitely regressions here, but there's also
a lot of things fixed. It's far too much work to let diverge anymore
regardless, so here it is.
The basic model is: A route has a fixed set of input channels (matching
its JACK input ports and diskstream). The first processor takes this
as input. The next processor is configured using the first processor's
output as input, and is allowed to choose whatever output it wants
given that input... and so on, and so on. Finally, the last processor's
requested output is used to set up the panner and create whatever Jack
ports are needed to output the data.
All 'special' internal processors (meter, fader, amp, insert, send) are
currently transparent: they read any input, and return the same set
of channels back (unmodified, except for amp).
User visible changes:
* LV2 Instrument support (tracks with both MIDI and audio channels)
* MIDI in/out plugin support
* Generic plugin replication (for MIDI plugins, MIDI/audio plugins)
* Movable meter point
Known Bugs:
* Things seem to get weird on loaded sessions
* Output delivery is sketchy
* 2.0 session loading was probably already broken...
but it's definitely broken now :)
Please test this and file bugs if you have any time...
git-svn-id: svn://localhost/ardour2/branches/3.0@5055 d708f5d6-7413-0410-9779-e7cbd77b26cf
2009-05-07 02:30:50 -04:00
|
|
|
#include "ardour/session.h"
|
2009-12-04 14:09:08 -05:00
|
|
|
#include "ardour/session_playlists.h"
|
2016-08-28 04:47:18 -04:00
|
|
|
#include "ardour/types_convert.h"
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/utils.h"
|
2022-12-18 17:40:53 -05:00
|
|
|
#include "ardour/velocity_control.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2012-05-24 02:09:29 -04:00
|
|
|
namespace ARDOUR {
|
|
|
|
class InterThreadInfo;
|
|
|
|
class MidiSource;
|
|
|
|
class Region;
|
|
|
|
class SMFSource;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
using namespace PBD;
|
|
|
|
|
2016-05-16 07:30:28 -04:00
|
|
|
MidiTrack::MidiTrack (Session& sess, string name, TrackMode mode)
|
|
|
|
: Track (sess, name, PresentationInfo::MidiTrack, mode, DataType::MIDI)
|
2016-12-07 13:47:04 -05:00
|
|
|
, _immediate_events(6096) // FIXME: size?
|
2023-09-14 01:57:49 -04:00
|
|
|
, _user_immediate_events(2048) // FIXME: size?
|
2017-09-30 17:16:04 -04:00
|
|
|
, _immediate_event_buffer(6096)
|
2023-09-14 01:57:49 -04:00
|
|
|
, _user_immediate_event_buffer(2048)
|
2009-09-03 08:39:50 -04:00
|
|
|
, _step_edit_ring_buffer(64) // FIXME: size?
|
2017-03-31 11:28:14 -04:00
|
|
|
, _note_mode (Sustained)
|
2009-09-03 08:39:50 -04:00
|
|
|
, _step_editing (false)
|
2011-07-01 11:48:24 -04:00
|
|
|
, _input_active (true)
|
2021-07-12 21:28:01 -04:00
|
|
|
, _restore_pgm_on_load (true)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2016-12-07 13:47:04 -05:00
|
|
|
_session.SessionLoaded.connect_same_thread (*this, boost::bind (&MidiTrack::restore_controls, this));
|
2019-11-02 21:35:25 -04:00
|
|
|
|
|
|
|
_playback_filter.ChannelModeChanged.connect_same_thread (*this, boost::bind (&Track::playlist_modified, this));
|
|
|
|
_playback_filter.ChannelMaskChanged.connect_same_thread (*this, boost::bind (&Track::playlist_modified, this));
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
MidiTrack::~MidiTrack ()
|
|
|
|
{
|
2023-06-09 21:09:41 -04:00
|
|
|
if (_freeze_record.playlist && !_session.deletion_in_progress()) {
|
|
|
|
_freeze_record.playlist->release();
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2011-07-01 11:48:24 -04:00
|
|
|
int
|
|
|
|
MidiTrack::init ()
|
|
|
|
{
|
|
|
|
if (Track::init ()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-12-18 17:40:53 -05:00
|
|
|
_velocity_control.reset (new VelocityControl (_session));
|
|
|
|
add_control (_velocity_control);
|
|
|
|
|
2011-07-01 11:48:24 -04:00
|
|
|
_input->changed.connect_same_thread (*this, boost::bind (&MidiTrack::track_input_active, this, _1, _2));
|
|
|
|
|
2017-06-12 15:38:59 -04:00
|
|
|
_disk_writer->set_note_mode (_note_mode);
|
|
|
|
_disk_reader->reset_tracker ();
|
|
|
|
|
2017-09-30 21:03:44 -04:00
|
|
|
_disk_writer->DataRecorded.connect_same_thread (*this, boost::bind (&MidiTrack::data_recorded, this, _1));
|
|
|
|
|
2021-07-22 20:05:11 -04:00
|
|
|
#ifdef HAVE_BEATBOX
|
2018-08-13 08:57:22 -04:00
|
|
|
_beatbox.reset (new BeatBox (_session));
|
|
|
|
add_processor (_beatbox, PostFader);
|
2021-07-22 20:05:11 -04:00
|
|
|
#endif
|
2018-08-13 08:57:22 -04:00
|
|
|
|
2011-07-01 11:48:24 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-09-30 21:03:44 -04:00
|
|
|
void
|
2023-02-16 18:33:28 -05:00
|
|
|
MidiTrack::data_recorded (std::weak_ptr<MidiSource> src)
|
2017-09-30 21:03:44 -04:00
|
|
|
{
|
|
|
|
DataRecorded (src); /* EMIT SIGNAL */
|
|
|
|
}
|
|
|
|
|
2016-04-08 16:49:47 -04:00
|
|
|
bool
|
|
|
|
MidiTrack::can_be_record_safe ()
|
2010-07-24 12:40:56 -04:00
|
|
|
{
|
2011-03-14 21:16:24 -04:00
|
|
|
if (_step_editing) {
|
2016-04-08 16:49:47 -04:00
|
|
|
return false;
|
2011-03-14 21:16:24 -04:00
|
|
|
}
|
2010-07-24 12:40:56 -04:00
|
|
|
|
2016-04-08 16:49:47 -04:00
|
|
|
return Track::can_be_record_safe ();
|
2010-07-24 12:40:56 -04:00
|
|
|
}
|
|
|
|
|
2016-04-08 16:49:47 -04:00
|
|
|
bool
|
|
|
|
MidiTrack::can_be_record_enabled ()
|
2015-06-16 08:44:03 -04:00
|
|
|
{
|
2016-04-08 16:49:47 -04:00
|
|
|
if (_step_editing) {
|
|
|
|
return false;
|
2015-06-16 08:44:03 -04:00
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2016-04-08 16:49:47 -04:00
|
|
|
return Track::can_be_record_enabled ();
|
2015-06-16 08:44:03 -04:00
|
|
|
}
|
|
|
|
|
2020-06-17 17:51:13 -04:00
|
|
|
MonitorState
|
|
|
|
MidiTrack::get_input_monitoring_state (bool recording, bool talkback) const
|
|
|
|
{
|
2022-09-19 15:46:36 -04:00
|
|
|
RecordMode rmode = _session.config.get_record_mode ();
|
2022-12-07 16:47:56 -05:00
|
|
|
if (rmode == RecSoundOnSound && (recording || talkback)) {
|
2020-06-17 17:51:13 -04:00
|
|
|
return MonitoringCue;
|
2022-09-19 15:46:36 -04:00
|
|
|
} else if (rmode != RecNonLayered || recording || talkback) {
|
2020-06-17 17:51:13 -04:00
|
|
|
return MonitoringInput;
|
|
|
|
} else {
|
|
|
|
return MonitoringSilence;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
int
|
2009-10-14 20:57:55 -04:00
|
|
|
MidiTrack::set_state (const XMLNode& node, int version)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2012-04-23 16:43:28 -04:00
|
|
|
/* This must happen before Track::set_state(), as there will be a buffer
|
|
|
|
fill during that call, and we must fill buffers using the correct
|
|
|
|
_note_mode.
|
|
|
|
*/
|
2016-08-28 04:47:18 -04:00
|
|
|
if (!node.get_property (X_("note-mode"), _note_mode)) {
|
2012-04-23 16:43:28 -04:00
|
|
|
_note_mode = Sustained;
|
|
|
|
}
|
|
|
|
|
2011-11-16 17:26:49 -05:00
|
|
|
if (Track::set_state (node, version)) {
|
2011-10-24 18:53:09 -04:00
|
|
|
return -1;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
// No destructive MIDI tracks (yet?)
|
|
|
|
_mode = Normal;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-08-28 04:47:18 -04:00
|
|
|
bool yn;
|
|
|
|
if (node.get_property ("input-active", yn)) {
|
|
|
|
set_input_active (yn);
|
2009-09-25 15:00:34 -04:00
|
|
|
}
|
|
|
|
|
2021-07-12 21:28:01 -04:00
|
|
|
if (node.get_property ("restore-pgm", yn)) {
|
|
|
|
set_restore_pgm_on_load (yn);
|
|
|
|
}
|
|
|
|
|
2013-03-27 21:50:18 -04:00
|
|
|
ChannelMode playback_channel_mode = AllChannels;
|
|
|
|
ChannelMode capture_channel_mode = AllChannels;
|
|
|
|
|
2016-08-28 04:47:18 -04:00
|
|
|
node.get_property ("playback-channel-mode", playback_channel_mode);
|
|
|
|
node.get_property ("capture-channel-mode", capture_channel_mode);
|
|
|
|
|
|
|
|
if (node.get_property ("channel-mode", playback_channel_mode)) {
|
2013-03-27 21:50:18 -04:00
|
|
|
/* 3.0 behaviour where capture and playback modes were not separated */
|
|
|
|
capture_channel_mode = playback_channel_mode;
|
|
|
|
}
|
|
|
|
|
2016-08-28 04:47:18 -04:00
|
|
|
XMLProperty const * prop;
|
|
|
|
|
2013-03-27 21:50:18 -04:00
|
|
|
unsigned int playback_channel_mask = 0xffff;
|
|
|
|
unsigned int capture_channel_mask = 0xffff;
|
|
|
|
|
|
|
|
if ((prop = node.property ("playback-channel-mask")) != 0) {
|
|
|
|
sscanf (prop->value().c_str(), "0x%x", &playback_channel_mask);
|
|
|
|
}
|
|
|
|
if ((prop = node.property ("capture-channel-mask")) != 0) {
|
|
|
|
sscanf (prop->value().c_str(), "0x%x", &capture_channel_mask);
|
|
|
|
}
|
|
|
|
if ((prop = node.property ("channel-mask")) != 0) {
|
|
|
|
sscanf (prop->value().c_str(), "0x%x", &playback_channel_mask);
|
|
|
|
capture_channel_mask = playback_channel_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_playback_channel_mode (playback_channel_mode, playback_channel_mask);
|
|
|
|
set_capture_channel_mode (capture_channel_mode, capture_channel_mask);
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
pending_state = const_cast<XMLNode*> (&node);
|
|
|
|
|
2019-03-18 10:33:05 -04:00
|
|
|
if (_session.loading ()) {
|
2011-03-14 21:16:24 -04:00
|
|
|
_session.StateReady.connect_same_thread (
|
|
|
|
*this, boost::bind (&MidiTrack::set_state_part_two, this));
|
2009-03-05 12:27:05 -05:00
|
|
|
} else {
|
|
|
|
set_state_part_two ();
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-14 12:10:01 -04:00
|
|
|
XMLNode&
|
2022-04-06 23:56:32 -04:00
|
|
|
MidiTrack::state(bool save_template) const
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2017-10-03 18:35:29 -04:00
|
|
|
XMLNode& root (Track::state (save_template));
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLNode* freeze_node;
|
|
|
|
char buf[64];
|
|
|
|
|
|
|
|
if (_freeze_record.playlist) {
|
|
|
|
XMLNode* inode;
|
|
|
|
|
|
|
|
freeze_node = new XMLNode (X_("freeze-info"));
|
2016-08-28 04:47:18 -04:00
|
|
|
freeze_node->set_property ("playlist", _freeze_record.playlist->name());
|
2021-05-31 17:40:16 -04:00
|
|
|
freeze_node->set_property ("playlist-id", _freeze_record.playlist->id().to_s());
|
2016-08-28 04:47:18 -04:00
|
|
|
freeze_node->set_property ("state", _freeze_record.state);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2022-04-06 23:56:32 -04:00
|
|
|
for (vector<FreezeRecordProcessorInfo*>::const_iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
|
2008-06-02 17:41:35 -04:00
|
|
|
inode = new XMLNode (X_("processor"));
|
2016-08-28 04:47:18 -04:00
|
|
|
inode->set_property (X_("id"), id());
|
2008-06-02 17:41:35 -04:00
|
|
|
inode->add_child_copy ((*i)->state);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
freeze_node->add_child_nocopy (*inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
root.add_child_nocopy (*freeze_node);
|
|
|
|
}
|
|
|
|
|
2017-05-25 07:39:59 -04:00
|
|
|
root.set_property("playback-channel-mode", get_playback_channel_mode());
|
|
|
|
root.set_property("capture-channel-mode", get_capture_channel_mode());
|
2013-03-27 21:50:18 -04:00
|
|
|
snprintf (buf, sizeof(buf), "0x%x", get_playback_channel_mask());
|
2016-08-28 04:47:18 -04:00
|
|
|
root.set_property("playback-channel-mask", std::string(buf));
|
2013-03-27 21:50:18 -04:00
|
|
|
snprintf (buf, sizeof(buf), "0x%x", get_capture_channel_mask());
|
2016-08-28 04:47:18 -04:00
|
|
|
root.set_property("capture-channel-mask", std::string(buf));
|
2013-03-27 21:50:18 -04:00
|
|
|
|
2016-08-28 04:47:18 -04:00
|
|
|
root.set_property ("note-mode", _note_mode);
|
|
|
|
root.set_property ("step-editing", _step_editing);
|
|
|
|
root.set_property ("input-active", _input_active);
|
2021-07-12 21:28:01 -04:00
|
|
|
root.set_property ("restore-pgm", _restore_pgm_on_load);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-12-07 13:47:04 -05:00
|
|
|
for (Controls::const_iterator c = _controls.begin(); c != _controls.end(); ++c) {
|
2023-02-16 18:33:28 -05:00
|
|
|
if (std::dynamic_pointer_cast<MidiTrack::MidiControl>(c->second)) {
|
|
|
|
std::shared_ptr<AutomationControl> ac = std::dynamic_pointer_cast<AutomationControl> (c->second);
|
2016-12-07 13:47:04 -05:00
|
|
|
assert (ac);
|
|
|
|
root.add_child_nocopy (ac->get_state ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return root;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::set_state_part_two ()
|
|
|
|
{
|
|
|
|
XMLNode* fnode;
|
2021-05-31 17:40:16 -04:00
|
|
|
XMLProperty const * prop;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
/* This is called after all session state has been restored but before
|
|
|
|
have been made ports and connections are established.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (pending_state == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((fnode = find_named_node (*pending_state, X_("freeze-info"))) != 0) {
|
|
|
|
|
|
|
|
_freeze_record.state = Frozen;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
for (vector<FreezeRecordProcessorInfo*>::iterator i = _freeze_record.processor_info.begin(); i != _freeze_record.processor_info.end(); ++i) {
|
|
|
|
delete *i;
|
|
|
|
}
|
|
|
|
_freeze_record.processor_info.clear ();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Playlist> freeze_pl;
|
2021-05-31 17:40:16 -04:00
|
|
|
if ((prop = fnode->property (X_("playlist-id"))) != 0) {
|
|
|
|
freeze_pl = _session.playlists()->by_id (prop->value());
|
|
|
|
} else if ((prop = fnode->property (X_("playlist"))) != 0) {
|
|
|
|
freeze_pl = _session.playlists()->by_name (prop->value());
|
|
|
|
}
|
|
|
|
if (freeze_pl) {
|
2023-02-16 18:33:28 -05:00
|
|
|
_freeze_record.playlist = std::dynamic_pointer_cast<MidiPlaylist> (freeze_pl);
|
2021-05-31 17:40:16 -04:00
|
|
|
_freeze_record.playlist->use();
|
|
|
|
} else {
|
|
|
|
_freeze_record.playlist.reset ();
|
|
|
|
_freeze_record.state = NoFreeze;
|
|
|
|
return;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2021-05-31 17:40:16 -04:00
|
|
|
|
2016-08-28 04:47:18 -04:00
|
|
|
fnode->get_property (X_("state"), _freeze_record.state);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
XMLNodeConstIterator citer;
|
|
|
|
XMLNodeList clist = fnode->children();
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2021-05-31 17:40:16 -04:00
|
|
|
std::string str;
|
2008-06-02 17:41:35 -04:00
|
|
|
for (citer = clist.begin(); citer != clist.end(); ++citer) {
|
|
|
|
if ((*citer)->name() != X_("processor")) {
|
|
|
|
continue;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-08-28 04:47:18 -04:00
|
|
|
if (!(*citer)->get_property (X_("id"), str)) {
|
2008-06-02 17:41:35 -04:00
|
|
|
continue;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
FreezeRecordProcessorInfo* frii = new FreezeRecordProcessorInfo (*((*citer)->children().front()),
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Processor>());
|
2016-08-28 04:47:18 -04:00
|
|
|
frii->id = str;
|
2008-06-02 17:41:35 -04:00
|
|
|
_freeze_record.processor_info.push_back (frii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-12-07 13:47:04 -05:00
|
|
|
void
|
|
|
|
MidiTrack::restore_controls ()
|
|
|
|
{
|
2021-07-12 21:28:01 -04:00
|
|
|
/* first CC (bank select) */
|
2016-12-07 13:47:04 -05:00
|
|
|
for (Controls::const_iterator c = _controls.begin(); c != _controls.end(); ++c) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiTrack::MidiControl> mctrl = std::dynamic_pointer_cast<MidiTrack::MidiControl>(c->second);
|
2021-07-12 21:28:01 -04:00
|
|
|
if (mctrl && mctrl->parameter().type () != MidiPgmChangeAutomation) {
|
|
|
|
mctrl->restore_value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!_restore_pgm_on_load) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* then restore PGM */
|
|
|
|
for (Controls::const_iterator c = _controls.begin(); c != _controls.end(); ++c) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiTrack::MidiControl> mctrl = std::dynamic_pointer_cast<MidiTrack::MidiControl>(c->second);
|
2021-07-12 21:28:01 -04:00
|
|
|
if (mctrl && mctrl->parameter().type () == MidiPgmChangeAutomation) {
|
2016-12-07 13:47:04 -05:00
|
|
|
mctrl->restore_value();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:47:34 -04:00
|
|
|
void
|
2017-09-30 17:16:04 -04:00
|
|
|
MidiTrack::update_controls (BufferSet const& bufs)
|
2015-03-26 00:47:34 -04:00
|
|
|
{
|
|
|
|
const MidiBuffer& buf = bufs.get_midi(0);
|
|
|
|
for (MidiBuffer::const_iterator e = buf.begin(); e != buf.end(); ++e) {
|
2017-09-30 17:16:04 -04:00
|
|
|
const Evoral::Event<samplepos_t>& ev = *e;
|
2015-03-26 00:47:34 -04:00
|
|
|
const Evoral::Parameter param = midi_parameter(ev.buffer(), ev.size());
|
2023-02-16 18:33:28 -05:00
|
|
|
const std::shared_ptr<AutomationControl> control = automation_control (param);
|
2015-03-26 00:47:34 -04:00
|
|
|
if (control) {
|
2022-06-28 19:17:03 -04:00
|
|
|
double old = control->get_double ();
|
2020-09-20 18:34:09 -04:00
|
|
|
control->set_double (ev.value(), timepos_t::zero (false), false);
|
2017-09-30 17:16:04 -04:00
|
|
|
if (old != ev.value()) {
|
|
|
|
control->Changed (false, Controllable::NoGroup);
|
|
|
|
}
|
2015-03-26 00:47:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 08:39:50 -04:00
|
|
|
int
|
2017-09-30 10:45:45 -04:00
|
|
|
MidiTrack::no_roll_unlocked (pframes_t nframes, samplepos_t start_sample, samplepos_t end_sample, bool state_changing)
|
2009-09-03 08:39:50 -04:00
|
|
|
{
|
2017-09-30 10:45:45 -04:00
|
|
|
int ret = Track::no_roll_unlocked (nframes, start_sample, end_sample, state_changing);
|
2009-09-03 08:39:50 -04:00
|
|
|
|
2010-07-24 12:40:56 -04:00
|
|
|
if (ret == 0 && _step_editing) {
|
2009-09-03 08:39:50 -04:00
|
|
|
push_midi_input_to_step_edit_ringbuffer (nframes);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-05-30 17:37:58 -04:00
|
|
|
void
|
2019-11-06 18:00:00 -05:00
|
|
|
MidiTrack::realtime_locate (bool for_loop_end)
|
2011-05-30 17:37:58 -04:00
|
|
|
{
|
2012-07-25 13:48:55 -04:00
|
|
|
Glib::Threads::RWLock::ReaderLock lm (_processor_lock, Glib::Threads::TRY_LOCK);
|
2011-12-26 12:01:31 -05:00
|
|
|
|
2011-05-30 17:37:58 -04:00
|
|
|
if (!lm.locked ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ProcessorList::iterator i = _processors.begin(); i != _processors.end(); ++i) {
|
2019-11-06 18:00:00 -05:00
|
|
|
(*i)->realtime_locate (for_loop_end);
|
2011-05-30 17:37:58 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:47:34 -04:00
|
|
|
void
|
2020-09-20 18:34:09 -04:00
|
|
|
MidiTrack::non_realtime_locate (samplepos_t spos)
|
2015-03-26 00:47:34 -04:00
|
|
|
{
|
2020-09-20 18:34:09 -04:00
|
|
|
timepos_t pos (spos);
|
|
|
|
|
|
|
|
Track::non_realtime_locate (spos);
|
2015-03-26 00:47:34 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiPlaylist> playlist = _disk_writer->midi_playlist();
|
2015-03-26 00:47:34 -04:00
|
|
|
if (!playlist) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the top unmuted region at this position. */
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiRegion> region = std::dynamic_pointer_cast<MidiRegion> (playlist->top_unmuted_region_at (pos));
|
2019-06-05 11:56:34 -04:00
|
|
|
|
2015-03-26 00:47:34 -04:00
|
|
|
if (!region) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-28 12:48:40 -04:00
|
|
|
/* the source may be missing, but the control still referenced in the GUI */
|
|
|
|
if (!region->midi_source() || !region->model()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-26 00:47:34 -04:00
|
|
|
Glib::Threads::Mutex::Lock lm (_control_lock, Glib::Threads::TRY_LOCK);
|
|
|
|
if (!lm.locked()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update track controllers based on its "automation". */
|
2020-09-20 18:34:09 -04:00
|
|
|
const timepos_t pos_beats = timepos_t (region->source_position().distance (pos).beats ()); /* relative to source start */
|
2019-06-05 12:02:27 -04:00
|
|
|
|
2015-03-26 00:47:34 -04:00
|
|
|
for (Controls::const_iterator c = _controls.begin(); c != _controls.end(); ++c) {
|
2019-06-05 12:02:27 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<AutomationControl> ac = std::dynamic_pointer_cast<AutomationControl> (c->second);
|
2019-06-05 12:02:27 -04:00
|
|
|
|
|
|
|
if (!ac->automation_playback()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiTrack::MidiControl> tcontrol;
|
|
|
|
std::shared_ptr<Evoral::Control> rcontrol;
|
2019-06-05 12:02:27 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
if ((tcontrol = std::dynamic_pointer_cast<MidiTrack::MidiControl>(c->second)) &&
|
2019-06-05 12:02:27 -04:00
|
|
|
|
2015-03-26 00:47:34 -04:00
|
|
|
(rcontrol = region->control(tcontrol->parameter()))) {
|
2020-09-20 18:34:09 -04:00
|
|
|
|
2015-08-23 20:42:31 -04:00
|
|
|
if (rcontrol->list()->size() > 0) {
|
2020-07-13 20:02:57 -04:00
|
|
|
tcontrol->set_value(rcontrol->list()->eval(pos_beats), Controllable::NoGroup);
|
2015-08-23 20:42:31 -04:00
|
|
|
}
|
2015-03-26 00:47:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 08:39:50 -04:00
|
|
|
void
|
2017-09-18 12:39:17 -04:00
|
|
|
MidiTrack::push_midi_input_to_step_edit_ringbuffer (samplecnt_t nframes)
|
2009-09-03 08:39:50 -04:00
|
|
|
{
|
|
|
|
PortSet& ports (_input->ports());
|
|
|
|
|
|
|
|
for (PortSet::iterator p = ports.begin(DataType::MIDI); p != ports.end(DataType::MIDI); ++p) {
|
|
|
|
|
|
|
|
Buffer& b (p->get_buffer (nframes));
|
|
|
|
const MidiBuffer* const mb = dynamic_cast<MidiBuffer*>(&b);
|
|
|
|
assert (mb);
|
|
|
|
|
|
|
|
for (MidiBuffer::const_iterator e = mb->begin(); e != mb->end(); ++e) {
|
|
|
|
|
2017-09-18 12:39:17 -04:00
|
|
|
const Evoral::Event<samplepos_t> ev(*e, false);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2011-03-14 21:16:24 -04:00
|
|
|
/* note on, since for step edit, note length is determined
|
2011-06-01 12:50:12 -04:00
|
|
|
elsewhere
|
2011-03-14 21:16:24 -04:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (ev.is_note_on()) {
|
|
|
|
/* we don't care about the time for this purpose */
|
2016-11-07 05:14:55 -05:00
|
|
|
_step_edit_ring_buffer.write (0, ev.event_type(), ev.size(), ev.buffer());
|
2011-03-14 21:16:24 -04:00
|
|
|
}
|
2009-09-03 08:39:50 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
2017-09-30 17:16:04 -04:00
|
|
|
MidiTrack::snapshot_out_of_band_data (samplecnt_t nframes)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2017-09-30 17:16:04 -04:00
|
|
|
_immediate_event_buffer.clear ();
|
|
|
|
if (0 == _immediate_events.read_space()) {
|
2023-09-14 01:57:49 -04:00
|
|
|
goto user;
|
2017-09-30 17:16:04 -04:00
|
|
|
}
|
2011-05-29 13:35:21 -04:00
|
|
|
|
2017-09-30 17:16:04 -04:00
|
|
|
assert (nframes > 0);
|
|
|
|
|
2019-10-29 23:36:09 -04:00
|
|
|
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of immediate events to deliver\n", name(), _immediate_events.read_space()));
|
2017-09-30 17:16:04 -04:00
|
|
|
|
|
|
|
/* write as many of the immediate events as we can, but give "true" as
|
|
|
|
* the last argument ("stop on overflow in destination") so that we'll
|
|
|
|
* ship the rest out next time.
|
|
|
|
*
|
2019-11-04 14:57:19 -05:00
|
|
|
* the (nframes-1) argument puts all these events at the last
|
2017-09-30 17:16:04 -04:00
|
|
|
* possible position of the output buffer, so that we do not
|
2019-11-04 14:57:19 -05:00
|
|
|
* violate monotonicity when writing.
|
2017-09-30 17:16:04 -04:00
|
|
|
*/
|
2019-11-04 14:57:19 -05:00
|
|
|
|
|
|
|
_immediate_events.read (_immediate_event_buffer, 0, 1, nframes - 1, true);
|
2023-09-14 01:57:49 -04:00
|
|
|
|
|
|
|
user:
|
|
|
|
_user_immediate_event_buffer.clear ();
|
|
|
|
if (0 == _user_immediate_events.read_space()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert (nframes > 0);
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 has %2 of user immediate events to deliver\n", name(), _user_immediate_events.read_space()));
|
|
|
|
|
|
|
|
/* write as many of the user immediate events as we can, but give "true" as
|
|
|
|
* the last argument ("stop on overflow in destination") so that we'll
|
|
|
|
* ship the rest out next time.
|
|
|
|
*
|
|
|
|
* the (nframes-1) argument puts all these events at the last
|
|
|
|
* possible position of the output buffer, so that we do not
|
|
|
|
* violate monotonicity when writing.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_user_immediate_events.read (_user_immediate_event_buffer, 0, 1, nframes - 1, true);
|
|
|
|
|
2017-09-30 17:16:04 -04:00
|
|
|
}
|
2011-05-29 13:35:21 -04:00
|
|
|
|
2017-09-30 17:16:04 -04:00
|
|
|
void
|
|
|
|
MidiTrack::write_out_of_band_data (BufferSet& bufs, samplecnt_t nframes) const
|
|
|
|
{
|
|
|
|
MidiBuffer& buf (bufs.get_midi (0));
|
|
|
|
buf.merge_from (_immediate_event_buffer, nframes);
|
2023-09-14 01:57:49 -04:00
|
|
|
buf.merge_from (_user_immediate_event_buffer, nframes);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2014-12-17 21:48:09 -05:00
|
|
|
MidiTrack::export_stuff (BufferSet& buffers,
|
2019-04-07 21:45:12 -04:00
|
|
|
samplepos_t start,
|
|
|
|
samplecnt_t nframes,
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<Processor> endpoint,
|
2014-12-17 21:48:09 -05:00
|
|
|
bool include_endpoint,
|
|
|
|
bool for_export,
|
2020-05-04 20:48:01 -04:00
|
|
|
bool for_freeze,
|
2022-02-01 18:20:28 -05:00
|
|
|
MidiNoteTracker& tracker)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-12-17 21:48:09 -05:00
|
|
|
if (buffers.count().n_midi() == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Glib::Threads::RWLock::ReaderLock rlock (_processor_lock);
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiPlaylist> mpl = _disk_writer->midi_playlist();
|
2014-12-17 21:48:09 -05:00
|
|
|
if (!mpl) {
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
|
|
|
buffers.get_midi(0).clear();
|
2020-05-03 19:24:37 -04:00
|
|
|
|
|
|
|
/* Can't use a note tracker here, because the note off's might be in a
|
|
|
|
* subsequent call
|
|
|
|
*/
|
|
|
|
|
2022-02-01 18:20:28 -05:00
|
|
|
MidiNoteTracker ignored;
|
2019-10-26 21:54:10 -04:00
|
|
|
|
2020-05-04 20:48:01 -04:00
|
|
|
/* XXX this doesn't fail, other than if the lock cannot be obtained */
|
|
|
|
mpl->rendered()->read (buffers.get_midi(0), start, start+nframes, ignored, start);
|
|
|
|
|
|
|
|
MidiBuffer& buf = buffers.get_midi(0);
|
2014-12-17 21:48:09 -05:00
|
|
|
|
2019-04-07 13:18:28 -04:00
|
|
|
if (endpoint && !for_export) {
|
|
|
|
for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) {
|
|
|
|
MidiBuffer::TimeType *t = i.timeptr ();
|
|
|
|
*t -= start;
|
|
|
|
}
|
|
|
|
bounce_process (buffers, start, nframes, endpoint, include_endpoint, for_export, for_freeze);
|
|
|
|
}
|
2014-12-17 21:48:09 -05:00
|
|
|
|
2020-05-04 20:48:01 -04:00
|
|
|
/* Add to tracker so that we can resolve at the end of the export (in Session::write_one_track()) */
|
|
|
|
|
|
|
|
for (MidiBuffer::iterator i = buf.begin(); i != buf.end(); ++i) {
|
|
|
|
tracker.track (*i);
|
|
|
|
}
|
|
|
|
|
2014-12-17 21:48:09 -05:00
|
|
|
return 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2023-10-16 11:22:53 -04:00
|
|
|
bool
|
|
|
|
MidiTrack::bounceable (std::shared_ptr<Processor> endpoint, bool include_endpoint) const
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2023-10-16 11:22:53 -04:00
|
|
|
if (!endpoint && !include_endpoint) {
|
|
|
|
/* no processing - just read from the playlist and create new
|
|
|
|
* files: always possible.
|
|
|
|
*/
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false; // a lie, Session::write_one_track can handle this.
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-03-02 13:05:26 -05:00
|
|
|
MidiTrack::freeze_me (InterThreadInfo& /*itt*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-10-07 17:35:33 -04:00
|
|
|
std::cerr << "MIDI freeze currently unsupported" << std::endl;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::unfreeze ()
|
|
|
|
{
|
|
|
|
_freeze_record.state = UnFrozen;
|
|
|
|
FreezeChange (); /* EMIT SIGNAL */
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::set_note_mode (NoteMode m)
|
|
|
|
{
|
|
|
|
_note_mode = m;
|
2017-03-31 11:28:14 -04:00
|
|
|
_disk_writer->set_note_mode(m);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2013-01-20 03:56:00 -05:00
|
|
|
std::string
|
|
|
|
MidiTrack::describe_parameter (Evoral::Parameter param)
|
|
|
|
{
|
|
|
|
const std::string str(instrument_info().get_controller_name(param));
|
|
|
|
return str.empty() ? Automatable::describe_parameter(param) : str;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
2009-10-14 12:10:01 -04:00
|
|
|
MidiTrack::midi_panic()
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2011-03-14 21:16:24 -04:00
|
|
|
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers panic data\n", name()));
|
2008-06-02 17:41:35 -04:00
|
|
|
for (uint8_t channel = 0; channel <= 0xF; channel++) {
|
2012-04-15 15:28:44 -04:00
|
|
|
uint8_t ev[3] = { ((uint8_t) (MIDI_CMD_CONTROL | channel)), ((uint8_t) MIDI_CTL_SUSTAIN), 0 };
|
2020-09-19 18:18:41 -04:00
|
|
|
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
|
2008-06-02 17:41:35 -04:00
|
|
|
ev[1] = MIDI_CTL_ALL_NOTES_OFF;
|
2020-09-19 18:18:41 -04:00
|
|
|
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
|
2008-06-02 17:41:35 -04:00
|
|
|
ev[1] = MIDI_CTL_RESET_CONTROLLERS;
|
2020-09-19 18:18:41 -04:00
|
|
|
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** \return true on success, false on failure (no buffer space left)
|
|
|
|
*/
|
|
|
|
bool
|
2020-09-19 18:18:41 -04:00
|
|
|
MidiTrack::write_immediate_event(Evoral::EventType event_type, size_t size, const uint8_t* buf)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2009-02-15 19:53:26 -05:00
|
|
|
if (!Evoral::midi_event_is_valid(buf, size)) {
|
|
|
|
cerr << "WARNING: Ignoring illegal immediate MIDI event" << endl;
|
|
|
|
return false;
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2020-09-19 18:18:41 -04:00
|
|
|
return (_immediate_events.write (0, event_type, size, buf) == size);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2023-09-14 01:57:49 -04:00
|
|
|
bool
|
|
|
|
MidiTrack::write_user_immediate_event(Evoral::EventType event_type, size_t size, const uint8_t* buf)
|
|
|
|
{
|
|
|
|
if (!Evoral::midi_event_is_valid(buf, size)) {
|
|
|
|
cerr << "WARNING: Ignoring illegal immediate MIDI event" << endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (_user_immediate_events.write (0, event_type, size, buf) == size);
|
|
|
|
}
|
|
|
|
|
2014-08-31 18:52:37 -04:00
|
|
|
void
|
|
|
|
MidiTrack::set_parameter_automation_state (Evoral::Parameter param, AutoState state)
|
|
|
|
{
|
|
|
|
switch (param.type()) {
|
|
|
|
case MidiCCAutomation:
|
|
|
|
case MidiPgmChangeAutomation:
|
|
|
|
case MidiPitchBenderAutomation:
|
|
|
|
case MidiChannelPressureAutomation:
|
2016-08-18 12:35:15 -04:00
|
|
|
case MidiNotePressureAutomation:
|
2014-08-31 18:52:37 -04:00
|
|
|
case MidiSystemExclusiveAutomation:
|
|
|
|
/* The track control for MIDI parameters is for immediate events to act
|
|
|
|
as a control surface, write/touch for them is not currently
|
|
|
|
supported. */
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
Automatable::set_parameter_automation_state(param, state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 13:47:04 -05:00
|
|
|
void
|
|
|
|
MidiTrack::MidiControl::restore_value ()
|
|
|
|
{
|
|
|
|
actually_set_value (get_value(), Controllable::NoGroup);
|
|
|
|
}
|
|
|
|
|
2016-10-14 11:16:42 -04:00
|
|
|
void
|
2016-04-08 16:49:47 -04:00
|
|
|
MidiTrack::MidiControl::actually_set_value (double val, PBD::Controllable::GroupControlDisposition group_override)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2014-10-16 15:21:11 -04:00
|
|
|
const Evoral::Parameter ¶meter = _list ? _list->parameter() : Control::parameter();
|
2014-12-01 14:28:03 -05:00
|
|
|
const Evoral::ParameterDescriptor &desc = EventTypeMap::instance().descriptor(parameter);
|
2014-10-16 15:21:11 -04:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
bool valid = false;
|
2014-11-01 13:35:44 -04:00
|
|
|
if (isinf_local(val)) {
|
2008-09-19 02:30:49 -04:00
|
|
|
cerr << "MIDIControl value is infinity" << endl;
|
2014-11-01 13:35:44 -04:00
|
|
|
} else if (isnan_local(val)) {
|
2008-09-19 02:30:49 -04:00
|
|
|
cerr << "MIDIControl value is NaN" << endl;
|
2014-12-01 14:28:03 -05:00
|
|
|
} else if (val < desc.lower) {
|
|
|
|
cerr << "MIDIControl value is < " << desc.lower << endl;
|
|
|
|
} else if (val > desc.upper) {
|
|
|
|
cerr << "MIDIControl value is > " << desc.upper << endl;
|
2008-09-19 02:30:49 -04:00
|
|
|
} else {
|
|
|
|
valid = true;
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-19 02:30:49 -04:00
|
|
|
if (!valid) {
|
2016-10-14 11:16:42 -04:00
|
|
|
return;
|
2008-09-19 02:30:49 -04:00
|
|
|
}
|
|
|
|
|
2021-07-12 21:28:01 -04:00
|
|
|
if (_session.loading ()) {
|
|
|
|
/* send events later in MidiTrack::restore_controls */
|
|
|
|
AutomationControl::actually_set_value (val, group_override);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-01 14:28:03 -05:00
|
|
|
assert(val <= desc.upper);
|
2021-07-12 21:28:01 -04:00
|
|
|
if (!_list || !automation_playback ()) {
|
2010-02-23 15:25:53 -05:00
|
|
|
size_t size = 3;
|
2014-10-16 15:21:11 -04:00
|
|
|
uint8_t ev[3] = { parameter.channel(), uint8_t (val), 0 };
|
|
|
|
switch(parameter.type()) {
|
2008-06-02 17:41:35 -04:00
|
|
|
case MidiCCAutomation:
|
2018-03-27 18:32:32 -04:00
|
|
|
ev[0] |= MIDI_CMD_CONTROL;
|
2014-10-16 15:21:11 -04:00
|
|
|
ev[1] = parameter.id();
|
2008-06-02 17:41:35 -04:00
|
|
|
ev[2] = int(val);
|
|
|
|
break;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
case MidiPgmChangeAutomation:
|
|
|
|
size = 2;
|
2018-03-27 18:32:32 -04:00
|
|
|
ev[0] |= MIDI_CMD_PGM_CHANGE;
|
2008-06-02 17:41:35 -04:00
|
|
|
ev[1] = int(val);
|
|
|
|
break;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-09-21 14:08:18 -04:00
|
|
|
case MidiChannelPressureAutomation:
|
2008-06-02 17:41:35 -04:00
|
|
|
size = 2;
|
2018-03-27 18:32:32 -04:00
|
|
|
ev[0] |= MIDI_CMD_CHANNEL_PRESSURE;
|
2008-06-02 17:41:35 -04:00
|
|
|
ev[1] = int(val);
|
|
|
|
break;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2016-08-18 12:35:15 -04:00
|
|
|
case MidiNotePressureAutomation:
|
2018-03-27 18:32:32 -04:00
|
|
|
ev[0] |= MIDI_CMD_NOTE_PRESSURE;
|
2016-08-18 12:35:15 -04:00
|
|
|
ev[1] = parameter.id();
|
|
|
|
ev[2] = int(val);
|
|
|
|
break;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
case MidiPitchBenderAutomation:
|
2018-03-27 18:32:32 -04:00
|
|
|
ev[0] |= MIDI_CMD_BENDER;
|
2008-06-02 17:41:35 -04:00
|
|
|
ev[1] = 0x7F & int(val);
|
|
|
|
ev[2] = 0x7F & (int(val) >> 7);
|
|
|
|
break;
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
default:
|
2018-03-27 18:32:32 -04:00
|
|
|
size = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
assert(false);
|
|
|
|
}
|
2020-09-19 16:49:52 -04:00
|
|
|
_route->write_immediate_event(Evoral::LIVE_MIDI_EVENT, size, ev);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2016-10-14 11:16:42 -04:00
|
|
|
AutomationControl::actually_set_value(val, group_override);
|
2009-10-14 12:10:01 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-09-03 08:39:50 -04:00
|
|
|
void
|
|
|
|
MidiTrack::set_step_editing (bool yn)
|
|
|
|
{
|
2011-03-14 21:16:24 -04:00
|
|
|
if (_session.record_status() != Session::Disabled) {
|
|
|
|
return;
|
|
|
|
}
|
2010-07-24 12:40:56 -04:00
|
|
|
|
2011-03-14 21:16:24 -04:00
|
|
|
if (yn != _step_editing) {
|
|
|
|
_step_editing = yn;
|
|
|
|
StepEditStatusChange (yn);
|
|
|
|
}
|
2009-09-03 08:39:50 -04:00
|
|
|
}
|
2009-09-25 15:00:34 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<SMFSource>
|
2010-09-02 13:01:36 -04:00
|
|
|
MidiTrack::write_source (uint32_t)
|
2010-04-21 16:42:22 -04:00
|
|
|
{
|
2017-03-31 11:28:14 -04:00
|
|
|
return _disk_writer->midi_write_source ();
|
2010-04-21 17:29:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-03-28 23:24:41 -04:00
|
|
|
MidiTrack::set_playback_channel_mode(ChannelMode mode, uint16_t mask)
|
2010-04-21 17:29:15 -04:00
|
|
|
{
|
2015-03-28 23:24:41 -04:00
|
|
|
if (_playback_filter.set_channel_mode(mode, mask)) {
|
|
|
|
_session.set_dirty();
|
2013-03-27 21:50:18 -04:00
|
|
|
}
|
2010-04-21 17:29:15 -04:00
|
|
|
}
|
|
|
|
|
2013-03-27 21:50:18 -04:00
|
|
|
void
|
2015-03-28 23:24:41 -04:00
|
|
|
MidiTrack::set_capture_channel_mode(ChannelMode mode, uint16_t mask)
|
2010-04-21 17:29:15 -04:00
|
|
|
{
|
2015-03-28 23:24:41 -04:00
|
|
|
if (_capture_filter.set_channel_mode(mode, mask)) {
|
|
|
|
_session.set_dirty();
|
2013-03-27 21:50:18 -04:00
|
|
|
}
|
2010-04-21 17:29:15 -04:00
|
|
|
}
|
|
|
|
|
2013-03-27 21:50:18 -04:00
|
|
|
void
|
|
|
|
MidiTrack::set_playback_channel_mask (uint16_t mask)
|
2010-04-21 17:29:15 -04:00
|
|
|
{
|
2015-03-28 23:24:41 -04:00
|
|
|
if (_playback_filter.set_channel_mask(mask)) {
|
|
|
|
_session.set_dirty();
|
2013-03-27 21:50:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::set_capture_channel_mask (uint16_t mask)
|
|
|
|
{
|
2015-03-28 23:24:41 -04:00
|
|
|
if (_capture_filter.set_channel_mask(mask)) {
|
|
|
|
_session.set_dirty();
|
2013-03-27 21:50:18 -04:00
|
|
|
}
|
2010-04-21 17:29:15 -04:00
|
|
|
}
|
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiPlaylist>
|
2010-04-21 17:29:15 -04:00
|
|
|
MidiTrack::midi_playlist ()
|
|
|
|
{
|
2023-02-16 18:33:28 -05:00
|
|
|
return std::dynamic_pointer_cast<MidiPlaylist> (_playlists[DataType::MIDI]);
|
2010-04-21 16:42:22 -04:00
|
|
|
}
|
2010-10-08 10:54:16 -04:00
|
|
|
|
2021-07-12 21:28:01 -04:00
|
|
|
void
|
|
|
|
MidiTrack::set_restore_pgm_on_load (bool yn)
|
|
|
|
{
|
|
|
|
if (_restore_pgm_on_load == yn) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_restore_pgm_on_load = yn;
|
|
|
|
_session.set_dirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
MidiTrack::restore_pgm_on_load () const
|
|
|
|
{
|
|
|
|
return _restore_pgm_on_load;
|
|
|
|
}
|
|
|
|
|
2011-07-01 11:48:24 -04:00
|
|
|
bool
|
|
|
|
MidiTrack::input_active () const
|
|
|
|
{
|
|
|
|
return _input_active;
|
|
|
|
}
|
|
|
|
|
2011-06-28 12:55:41 -04:00
|
|
|
void
|
|
|
|
MidiTrack::set_input_active (bool yn)
|
2011-07-01 11:48:24 -04:00
|
|
|
{
|
|
|
|
if (yn != _input_active) {
|
|
|
|
_input_active = yn;
|
|
|
|
map_input_active (yn);
|
|
|
|
InputActiveChanged (); /* EMIT SIGNAL */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::map_input_active (bool yn)
|
2011-06-28 12:55:41 -04:00
|
|
|
{
|
|
|
|
if (!_input) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
PortSet& ports (_input->ports());
|
|
|
|
|
|
|
|
for (PortSet::iterator p = ports.begin(DataType::MIDI); p != ports.end(DataType::MIDI); ++p) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiPort> mp = std::dynamic_pointer_cast<MidiPort> (*p);
|
2011-06-28 12:55:41 -04:00
|
|
|
if (yn != mp->input_active()) {
|
|
|
|
mp->set_input_active (yn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-01 11:48:24 -04:00
|
|
|
void
|
|
|
|
MidiTrack::track_input_active (IOChange change, void* /* src */)
|
2011-06-28 12:55:41 -04:00
|
|
|
{
|
2011-07-01 11:48:24 -04:00
|
|
|
if (change.type & IOChange::ConfigurationChanged) {
|
|
|
|
map_input_active (_input_active);
|
2011-06-28 12:55:41 -04:00
|
|
|
}
|
|
|
|
}
|
2011-07-01 11:48:24 -04:00
|
|
|
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiBuffer>
|
2011-11-04 13:52:12 -04:00
|
|
|
MidiTrack::get_gui_feed_buffer () const
|
|
|
|
{
|
2017-09-30 21:30:02 -04:00
|
|
|
return _disk_writer->get_gui_feed_buffer ();
|
2011-11-04 13:52:12 -04:00
|
|
|
}
|
2011-12-14 12:17:30 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::act_on_mute ()
|
|
|
|
{
|
|
|
|
/* this is called right after our mute status has changed.
|
|
|
|
if we are now muted, send suitable output to shutdown
|
|
|
|
all our notes.
|
|
|
|
|
|
|
|
XXX we should should also stop all relevant note trackers.
|
|
|
|
*/
|
|
|
|
|
2012-07-04 15:56:14 -04:00
|
|
|
/* If we haven't got a diskstream yet, there's nothing to worry about,
|
|
|
|
and we can't call get_channel_mask() anyway.
|
|
|
|
*/
|
2017-03-31 11:28:14 -04:00
|
|
|
if (!_disk_writer) {
|
2012-07-04 15:56:14 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-20 23:22:29 -04:00
|
|
|
if (muted() || _mute_master->muted_by_others_soloing_at (MuteMaster::AllPoints)) {
|
2011-12-14 12:17:30 -05:00
|
|
|
/* only send messages for channels we are using */
|
|
|
|
|
2015-03-28 23:24:41 -04:00
|
|
|
uint16_t mask = _playback_filter.get_channel_mask();
|
2011-12-14 12:17:30 -05:00
|
|
|
|
|
|
|
for (uint8_t channel = 0; channel <= 0xF; channel++) {
|
|
|
|
|
|
|
|
if ((1<<channel) & mask) {
|
|
|
|
|
|
|
|
DEBUG_TRACE (DEBUG::MidiIO, string_compose ("%1 delivers mute message to channel %2\n", name(), channel+1));
|
2012-04-15 15:28:44 -04:00
|
|
|
uint8_t ev[3] = { ((uint8_t) (MIDI_CMD_CONTROL | channel)), MIDI_CTL_SUSTAIN, 0 };
|
2020-09-19 18:18:41 -04:00
|
|
|
write_immediate_event (Evoral::MIDI_EVENT, 3, ev);
|
2015-03-24 13:47:37 -04:00
|
|
|
|
|
|
|
/* Note we do not send MIDI_CTL_ALL_NOTES_OFF here, since this may
|
|
|
|
silence notes that came from another non-muted track. */
|
2011-12-14 12:17:30 -05:00
|
|
|
}
|
|
|
|
}
|
2015-03-24 13:47:37 -04:00
|
|
|
|
|
|
|
/* Resolve active notes. */
|
2019-11-04 14:57:19 -05:00
|
|
|
_disk_reader->resolve_tracker (_immediate_events, 0);
|
2011-12-14 12:17:30 -05:00
|
|
|
}
|
|
|
|
}
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2011-12-26 12:01:31 -05:00
|
|
|
void
|
2016-04-08 16:49:47 -04:00
|
|
|
MidiTrack::monitoring_changed (bool self, Controllable::GroupControlDisposition gcd)
|
2011-12-26 12:01:31 -05:00
|
|
|
{
|
2016-04-08 16:49:47 -04:00
|
|
|
Track::monitoring_changed (self, gcd);
|
2016-04-20 23:22:29 -04:00
|
|
|
|
2016-04-08 16:49:47 -04:00
|
|
|
/* monitoring state changed, so flush out any on notes at the
|
|
|
|
* port level.
|
|
|
|
*/
|
2011-12-26 12:01:31 -05:00
|
|
|
|
2016-04-08 16:49:47 -04:00
|
|
|
PortSet& ports (_output->ports());
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2016-04-08 16:49:47 -04:00
|
|
|
for (PortSet::iterator p = ports.begin(); p != ports.end(); ++p) {
|
2023-02-16 18:33:28 -05:00
|
|
|
std::shared_ptr<MidiPort> mp = std::dynamic_pointer_cast<MidiPort> (*p);
|
2016-04-08 16:49:47 -04:00
|
|
|
if (mp) {
|
|
|
|
mp->require_resolve ();
|
2012-06-18 15:20:59 -04:00
|
|
|
}
|
2016-04-08 16:49:47 -04:00
|
|
|
}
|
2012-06-18 15:20:59 -04:00
|
|
|
|
2017-03-31 11:28:14 -04:00
|
|
|
_disk_reader->reset_tracker ();
|
2011-12-26 12:01:31 -05:00
|
|
|
}
|
2012-01-09 11:43:30 -05:00
|
|
|
|
2012-12-18 20:20:37 -05:00
|
|
|
MonitorState
|
|
|
|
MidiTrack::monitoring_state () const
|
|
|
|
{
|
|
|
|
MonitorState ms = Track::monitoring_state();
|
|
|
|
if (ms == MonitoringSilence) {
|
2020-06-17 17:51:13 -04:00
|
|
|
/* MIDI always monitor input as fallback */
|
2012-12-18 20:20:37 -05:00
|
|
|
return MonitoringInput;
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2012-12-18 20:20:37 -05:00
|
|
|
return ms;
|
|
|
|
}
|
2017-09-18 21:27:55 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::filter_input (BufferSet& bufs)
|
|
|
|
{
|
|
|
|
_capture_filter.filter (bufs);
|
|
|
|
}
|
2019-10-15 18:57:23 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
MidiTrack::realtime_handle_transport_stopped ()
|
|
|
|
{
|
|
|
|
Route::realtime_handle_transport_stopped ();
|
2019-11-04 14:57:19 -05:00
|
|
|
_disk_reader->resolve_tracker (_immediate_events, 0);
|
2023-09-14 01:57:49 -04:00
|
|
|
_disk_reader->resolve_tracker (_user_immediate_events, 0);
|
2019-10-15 18:57:23 -04:00
|
|
|
}
|
2019-10-17 19:32:56 -04:00
|
|
|
|
|
|
|
void
|
2019-10-18 19:21:51 -04:00
|
|
|
MidiTrack::playlist_contents_changed ()
|
2019-10-17 19:32:56 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
}
|