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 <jack/jack.h>
26 #include <jack/transport.h>
28 #include "ardour/audioengine.h"
29 #include "ardour/filename_extensions.h"
30 #include "ardour/session.h"
31 #include "ardour/session_directory.h"
32 #include "ardour/tempo.h"
34 #include "jack_session.h"
36 using namespace ARDOUR;
39 JACKSession::JACKSession (Session* s)
40 : SessionHandlePtr (s)
44 JACKSession::~JACKSession ()
49 JACKSession::session_event (jack_session_event_t* event)
51 char timebuf[128], *tmp;
56 localtime_r (&n, &local_time);
57 strftime (timebuf, sizeof(timebuf), "JS_%FT%T", &local_time);
59 while ((tmp = strchr(timebuf, ':'))) { *tmp = '.'; }
61 if (event->type == JackSessionSaveTemplate)
63 if (_session->save_template( timebuf )) {
64 event->flags = JackSessionSaveError;
66 string cmd ("ardour3 -P -U ");
67 cmd += event->client_uuid;
71 event->command_line = strdup (cmd.c_str());
76 if (_session->save_state (timebuf)) {
77 event->flags = JackSessionSaveError;
79 std::string xml_path (_session->session_directory().root_path());
80 std::string legalized_filename = legalize_for_path (timebuf) + statefile_suffix;
81 xml_path = Glib::build_filename (xml_path, legalized_filename);
83 string cmd ("ardour3 -P -U ");
84 cmd += event->client_uuid;
89 event->command_line = strdup (cmd.c_str());
93 /* this won't be called if the port engine in use is not JACK, so we do
94 not have to worry about the type of PortEngine::private_handle()
97 jack_client_t* jack_client = (jack_client_t*) AudioEngine::instance()->port_engine().private_handle();
100 jack_session_reply (jack_client, event);
103 if (event->type == JackSessionSaveAndQuit) {
104 _session->Quit (); /* EMIT SIGNAL */
107 jack_session_event_free (event);
111 JACKSession::timebase_callback (jack_transport_state_t /*state*/,
112 pframes_t /*nframes*/,
113 jack_position_t* pos,
114 int /*new_position*/)
116 Timecode::BBT_Time bbt;
117 TempoMap& tempo_map (_session->tempo_map());
118 framepos_t tf = _session->transport_frame ();
122 TempoMetric metric (tempo_map.metric_at (tf));
125 tempo_map.bbt_time_rt (tf, bbt);
128 pos->beat = bbt.beats;
129 pos->tick = bbt.ticks;
131 // XXX still need to set bar_start_tick
133 pos->beats_per_bar = metric.meter().divisions_per_bar();
134 pos->beat_type = metric.meter().note_divisor();
135 pos->ticks_per_beat = Timecode::BBT_Time::ticks_per_beat;
136 pos->beats_per_minute = metric.tempo().beats_per_minute();
138 pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT);
144 #ifdef HAVE_JACK_VIDEO_SUPPORT
145 //poke audio video ratio so Ardour can track Video Sync
146 pos->audio_frames_per_video_frame = _session->frame_rate() / _session->timecode_frames_per_second();
147 pos->valid = jack_position_bits_t (pos->valid | JackAudioVideoRatio);
150 #ifdef HAVE_JACK_TIMCODE_SUPPORT
151 /* This is not yet defined in JACK */
155 pos->timecode_offset = _session->config.get_timecode_offset();
156 t.timecode_frame_rate = _session->timecode_frames_per_second();
157 pos->valid = jack_position_bits_t (pos->valid | JackPositionTimecode);
160 #ifdef HAVE_JACK_LOOPING_SUPPORT
161 /* This is not yet defined in JACK */
162 if (_transport_speed) {
166 Location* location = _session->locations()->auto_loop_location();
170 t.transport_state = JackTransportLooping;
171 t.loop_start = location->start();
172 t.loop_end = location->end();
173 t.valid = jack_transport_bits_t (t.valid | JackTransportLoop);
179 t.transport_state = JackTransportRolling;
187 t.transport_state = JackTransportRolling;