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 "pbd/localtime_r.h"
30 #include "ardour/audioengine.h"
31 #include "ardour/filename_extensions.h"
32 #include "ardour/session.h"
33 #include "ardour/session_directory.h"
34 #include "ardour/tempo.h"
36 #include "jack_session.h"
38 using namespace ARDOUR;
41 JACKSession::JACKSession (Session* s)
42 : SessionHandlePtr (s)
46 JACKSession::~JACKSession ()
51 JACKSession::session_event (jack_session_event_t* event)
53 char timebuf[128], *tmp;
58 localtime_r (&n, &local_time);
59 strftime (timebuf, sizeof(timebuf), "JS_%FT%T", &local_time);
61 while ((tmp = strchr(timebuf, ':'))) { *tmp = '.'; }
63 if (event->type == JackSessionSaveTemplate)
65 if (_session->save_template( timebuf )) {
66 event->flags = JackSessionSaveError;
68 string cmd ("ardour3 -P -U ");
69 cmd += event->client_uuid;
73 event->command_line = strdup (cmd.c_str());
78 if (_session->save_state (timebuf)) {
79 event->flags = JackSessionSaveError;
81 std::string xml_path (_session->session_directory().root_path());
82 std::string legalized_filename = legalize_for_path (timebuf) + statefile_suffix;
83 xml_path = Glib::build_filename (xml_path, legalized_filename);
85 string cmd ("ardour3 -P -U ");
86 cmd += event->client_uuid;
91 event->command_line = strdup (cmd.c_str());
95 /* this won't be called if the port engine in use is not JACK, so we do
96 not have to worry about the type of PortEngine::private_handle()
99 jack_client_t* jack_client = (jack_client_t*) AudioEngine::instance()->port_engine().private_handle();
102 jack_session_reply (jack_client, event);
105 if (event->type == JackSessionSaveAndQuit) {
106 _session->Quit (); /* EMIT SIGNAL */
109 jack_session_event_free (event);
113 JACKSession::timebase_callback (jack_transport_state_t /*state*/,
114 pframes_t /*nframes*/,
115 jack_position_t* pos,
116 int /*new_position*/)
118 Timecode::BBT_Time bbt;
119 TempoMap& tempo_map (_session->tempo_map());
120 framepos_t tf = _session->transport_frame ();
124 TempoMetric metric (tempo_map.metric_at (tf));
127 tempo_map.bbt_time_rt (tf, bbt);
130 pos->beat = bbt.beats;
131 pos->tick = bbt.ticks;
133 // XXX still need to set bar_start_tick
135 pos->beats_per_bar = metric.meter().divisions_per_bar();
136 pos->beat_type = metric.meter().note_divisor();
137 pos->ticks_per_beat = Timecode::BBT_Time::ticks_per_beat;
138 pos->beats_per_minute = metric.tempo().beats_per_minute();
140 pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT);
146 #ifdef HAVE_JACK_VIDEO_SUPPORT
147 //poke audio video ratio so Ardour can track Video Sync
148 pos->audio_frames_per_video_frame = _session->frame_rate() / _session->timecode_frames_per_second();
149 pos->valid = jack_position_bits_t (pos->valid | JackAudioVideoRatio);
152 #ifdef HAVE_JACK_TIMCODE_SUPPORT
153 /* This is not yet defined in JACK */
157 pos->timecode_offset = _session->config.get_timecode_offset();
158 t.timecode_frame_rate = _session->timecode_frames_per_second();
159 pos->valid = jack_position_bits_t (pos->valid | JackPositionTimecode);
162 #ifdef HAVE_JACK_LOOPING_SUPPORT
163 /* This is not yet defined in JACK */
164 if (_transport_speed) {
168 Location* location = _session->locations()->auto_loop_location();
172 t.transport_state = JackTransportLooping;
173 t.loop_start = location->start();
174 t.loop_end = location->end();
175 t.valid = jack_transport_bits_t (t.valid | JackTransportLoop);
181 t.transport_state = JackTransportRolling;
189 t.transport_state = JackTransportRolling;