2013-08-09 12:15:37 -04:00
|
|
|
/*
|
2019-08-02 22:11:41 -04:00
|
|
|
* Copyright (C) 2013-2017 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2014-2017 Robin Gareus <robin@gareus.org>
|
|
|
|
* Copyright (C) 2015-2016 Nick Mainsbridge <mainsbridge@gmail.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.
|
|
|
|
*/
|
2013-08-09 12:15:37 -04:00
|
|
|
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <glibmm/miscutils.h>
|
|
|
|
|
2013-09-27 08:52:32 -04:00
|
|
|
#include "pbd/localtime_r.h"
|
|
|
|
|
2013-08-09 12:15:37 -04:00
|
|
|
#include "ardour/audioengine.h"
|
|
|
|
#include "ardour/filename_extensions.h"
|
|
|
|
#include "ardour/session.h"
|
|
|
|
#include "ardour/session_directory.h"
|
|
|
|
#include "ardour/tempo.h"
|
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
#include "jack_session.h"
|
|
|
|
|
2013-08-09 12:15:37 -04:00
|
|
|
using namespace ARDOUR;
|
2020-11-11 11:31:52 -05:00
|
|
|
using namespace Temporal;
|
2013-08-09 12:15:37 -04:00
|
|
|
using std::string;
|
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
JACKSession::JACKSession (Session* s)
|
|
|
|
: SessionHandlePtr (s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
JACKSession::~JACKSession ()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-08-09 12:15:37 -04:00
|
|
|
void
|
2013-10-08 14:01:43 -04:00
|
|
|
JACKSession::session_event (jack_session_event_t* event)
|
2013-08-09 12:15:37 -04:00
|
|
|
{
|
|
|
|
char timebuf[128], *tmp;
|
|
|
|
time_t n;
|
|
|
|
struct tm local_time;
|
|
|
|
|
|
|
|
time (&n);
|
|
|
|
localtime_r (&n, &local_time);
|
|
|
|
strftime (timebuf, sizeof(timebuf), "JS_%FT%T", &local_time);
|
|
|
|
|
|
|
|
while ((tmp = strchr(timebuf, ':'))) { *tmp = '.'; }
|
|
|
|
|
|
|
|
if (event->type == JackSessionSaveTemplate)
|
|
|
|
{
|
2013-10-08 14:01:43 -04:00
|
|
|
if (_session->save_template( timebuf )) {
|
2013-08-09 12:15:37 -04:00
|
|
|
event->flags = JackSessionSaveError;
|
|
|
|
} else {
|
|
|
|
string cmd ("ardour3 -P -U ");
|
|
|
|
cmd += event->client_uuid;
|
|
|
|
cmd += " -T ";
|
|
|
|
cmd += timebuf;
|
|
|
|
|
|
|
|
event->command_line = strdup (cmd.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-08 14:01:43 -04:00
|
|
|
if (_session->save_state (timebuf)) {
|
2013-08-09 12:15:37 -04:00
|
|
|
event->flags = JackSessionSaveError;
|
|
|
|
} else {
|
2013-10-08 14:01:43 -04:00
|
|
|
std::string xml_path (_session->session_directory().root_path());
|
2013-08-09 12:15:37 -04:00
|
|
|
std::string legalized_filename = legalize_for_path (timebuf) + statefile_suffix;
|
|
|
|
xml_path = Glib::build_filename (xml_path, legalized_filename);
|
|
|
|
|
|
|
|
string cmd ("ardour3 -P -U ");
|
|
|
|
cmd += event->client_uuid;
|
|
|
|
cmd += " \"";
|
|
|
|
cmd += xml_path;
|
|
|
|
cmd += '\"';
|
|
|
|
|
|
|
|
event->command_line = strdup (cmd.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* this won't be called if the port engine in use is not JACK, so we do
|
2013-08-09 12:15:37 -04:00
|
|
|
not have to worry about the type of PortEngine::private_handle()
|
|
|
|
*/
|
|
|
|
|
|
|
|
jack_client_t* jack_client = (jack_client_t*) AudioEngine::instance()->port_engine().private_handle();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-08-09 12:15:37 -04:00
|
|
|
if (jack_client) {
|
|
|
|
jack_session_reply (jack_client, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (event->type == JackSessionSaveAndQuit) {
|
2013-10-08 14:01:43 -04:00
|
|
|
_session->Quit (); /* EMIT SIGNAL */
|
2013-08-09 12:15:37 -04:00
|
|
|
}
|
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
jack_session_event_free (event);
|
2013-08-09 12:15:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-08 14:01:43 -04:00
|
|
|
JACKSession::timebase_callback (jack_transport_state_t /*state*/,
|
2013-08-09 12:15:37 -04:00
|
|
|
pframes_t /*nframes*/,
|
|
|
|
jack_position_t* pos,
|
|
|
|
int /*new_position*/)
|
|
|
|
{
|
2020-07-23 19:46:49 -04:00
|
|
|
Temporal::BBT_Time bbt;
|
2020-11-27 14:40:58 -05:00
|
|
|
TempoMap::SharedPtr tempo_map (TempoMap::use());
|
2019-11-11 20:21:47 -05:00
|
|
|
samplepos_t tf;
|
|
|
|
|
|
|
|
/* see commit msg for e2c26e1b9 and Session::start_locate() for
|
|
|
|
details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
tf = _session->nominal_jack_transport_sample().value_or (_session->transport_sample());
|
2013-08-09 12:15:37 -04:00
|
|
|
|
|
|
|
/* BBT info */
|
|
|
|
|
2020-11-27 14:40:58 -05:00
|
|
|
TempoMetric metric (tempo_map->metric_at (tf));
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
try {
|
2020-11-27 14:40:58 -05:00
|
|
|
bbt = tempo_map->bbt_at (tf);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
pos->bar = bbt.bars;
|
|
|
|
pos->beat = bbt.beats;
|
|
|
|
pos->tick = bbt.ticks;
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
pos->beats_per_bar = metric.meter().divisions_per_bar();
|
2020-11-11 11:31:52 -05:00
|
|
|
pos->beat_type = metric.meter().note_value();
|
2020-07-23 19:46:49 -04:00
|
|
|
pos->ticks_per_beat = Temporal::ticks_per_beat;
|
2016-11-05 14:14:20 -04:00
|
|
|
pos->beats_per_minute = metric.tempo().note_types_per_minute();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2020-12-06 18:33:34 -05:00
|
|
|
Beats current_tick = metric.quarters_at (bbt) / 4 * pos->beat_type * pos->ticks_per_beat;
|
|
|
|
pos->bar_start_tick = current_tick.to_ticks() - ((pos->beat - 1) * pos->ticks_per_beat + pos->tick);
|
2020-07-20 08:59:28 -04:00
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
} catch (...) {
|
|
|
|
/* no message */
|
2013-08-09 12:15:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_JACK_VIDEO_SUPPORT
|
|
|
|
//poke audio video ratio so Ardour can track Video Sync
|
2017-09-19 12:40:29 -04:00
|
|
|
pos->audio_frames_per_video_frame = _session->sample_rate() / _session->timecode_frames_per_second();
|
2013-08-09 12:15:37 -04:00
|
|
|
pos->valid = jack_position_bits_t (pos->valid | JackAudioVideoRatio);
|
|
|
|
#endif
|
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
#ifdef HAVE_JACK_TIMCODE_SUPPORT
|
|
|
|
/* This is not yet defined in JACK */
|
|
|
|
|
2013-08-09 12:15:37 -04:00
|
|
|
/* Timecode info */
|
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
pos->timecode_offset = _session->config.get_timecode_offset();
|
|
|
|
t.timecode_frame_rate = _session->timecode_frames_per_second();
|
|
|
|
pos->valid = jack_position_bits_t (pos->valid | JackPositionTimecode);
|
|
|
|
#endif
|
2013-08-09 12:15:37 -04:00
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
#ifdef HAVE_JACK_LOOPING_SUPPORT
|
|
|
|
/* This is not yet defined in JACK */
|
2013-08-09 12:15:37 -04:00
|
|
|
if (_transport_speed) {
|
|
|
|
|
|
|
|
if (play_loop) {
|
|
|
|
|
2013-10-08 14:01:43 -04:00
|
|
|
Location* location = _session->locations()->auto_loop_location();
|
2013-08-09 12:15:37 -04:00
|
|
|
|
|
|
|
if (location) {
|
|
|
|
|
|
|
|
t.transport_state = JackTransportLooping;
|
|
|
|
t.loop_start = location->start();
|
|
|
|
t.loop_end = location->end();
|
|
|
|
t.valid = jack_transport_bits_t (t.valid | JackTransportLoop);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
t.loop_start = 0;
|
|
|
|
t.loop_end = 0;
|
|
|
|
t.transport_state = JackTransportRolling;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
t.loop_start = 0;
|
|
|
|
t.loop_end = 0;
|
|
|
|
t.transport_state = JackTransportRolling;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|