2 Copyright (C) 2013 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <glibmm/miscutils.h>
25 #include "pbd/localtime_r.h"
27 #include "ardour/audioengine.h"
28 #include "ardour/filename_extensions.h"
29 #include "ardour/session.h"
30 #include "ardour/session_directory.h"
31 #include "ardour/tempo.h"
33 #include "jack_session.h"
35 using namespace ARDOUR;
38 JACKSession::JACKSession (Session* s)
39 : SessionHandlePtr (s)
43 JACKSession::~JACKSession ()
48 JACKSession::session_event (jack_session_event_t* event)
50 char timebuf[128], *tmp;
55 localtime_r (&n, &local_time);
56 strftime (timebuf, sizeof(timebuf), "JS_%FT%T", &local_time);
58 while ((tmp = strchr(timebuf, ':'))) { *tmp = '.'; }
60 if (event->type == JackSessionSaveTemplate)
62 if (_session->save_template( timebuf )) {
63 event->flags = JackSessionSaveError;
65 string cmd ("ardour3 -P -U ");
66 cmd += event->client_uuid;
70 event->command_line = strdup (cmd.c_str());
75 if (_session->save_state (timebuf)) {
76 event->flags = JackSessionSaveError;
78 std::string xml_path (_session->session_directory().root_path());
79 std::string legalized_filename = legalize_for_path (timebuf) + statefile_suffix;
80 xml_path = Glib::build_filename (xml_path, legalized_filename);
82 string cmd ("ardour3 -P -U ");
83 cmd += event->client_uuid;
88 event->command_line = strdup (cmd.c_str());
92 /* this won't be called if the port engine in use is not JACK, so we do
93 not have to worry about the type of PortEngine::private_handle()
96 jack_client_t* jack_client = (jack_client_t*) AudioEngine::instance()->port_engine().private_handle();
99 jack_session_reply (jack_client, event);
102 if (event->type == JackSessionSaveAndQuit) {
103 _session->Quit (); /* EMIT SIGNAL */
106 jack_session_event_free (event);
110 JACKSession::timebase_callback (jack_transport_state_t /*state*/,
111 pframes_t /*nframes*/,
112 jack_position_t* pos,
113 int /*new_position*/)
115 Timecode::BBT_Time bbt;
116 TempoMap& tempo_map (_session->tempo_map());
117 framepos_t tf = _session->transport_frame ();
121 TempoMetric metric (tempo_map.metric_at (tf));
124 tempo_map.bbt_time (tf, bbt);
127 pos->beat = bbt.beats;
128 pos->tick = bbt.ticks;
130 // XXX still need to set bar_start_tick
132 pos->beats_per_bar = metric.meter().divisions_per_bar();
133 pos->beat_type = metric.meter().note_divisor();
134 pos->ticks_per_beat = Timecode::BBT_Time::ticks_per_beat;
135 pos->beats_per_minute = metric.tempo().beats_per_minute();
137 pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT);
143 #ifdef HAVE_JACK_VIDEO_SUPPORT
144 //poke audio video ratio so Ardour can track Video Sync
145 pos->audio_frames_per_video_frame = _session->frame_rate() / _session->timecode_frames_per_second();
146 pos->valid = jack_position_bits_t (pos->valid | JackAudioVideoRatio);
149 #ifdef HAVE_JACK_TIMCODE_SUPPORT
150 /* This is not yet defined in JACK */
154 pos->timecode_offset = _session->config.get_timecode_offset();
155 t.timecode_frame_rate = _session->timecode_frames_per_second();
156 pos->valid = jack_position_bits_t (pos->valid | JackPositionTimecode);
159 #ifdef HAVE_JACK_LOOPING_SUPPORT
160 /* This is not yet defined in JACK */
161 if (_transport_speed) {
165 Location* location = _session->locations()->auto_loop_location();
169 t.transport_state = JackTransportLooping;
170 t.loop_start = location->start();
171 t.loop_end = location->end();
172 t.valid = jack_transport_bits_t (t.valid | JackTransportLoop);
178 t.transport_state = JackTransportRolling;
186 t.transport_state = JackTransportRolling;