2 Copyright (C) 1999-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.
22 #include "libardour-config.h"
27 #include <glibmm/miscutils.h>
29 #include "jack/jack.h"
30 #include "jack/session.h"
32 #include "ardour/audioengine.h"
33 #include "ardour/filename_extensions.h"
34 #include "ardour/session.h"
35 #include "ardour/session_directory.h"
36 #include "ardour/tempo.h"
38 using namespace ARDOUR;
41 #ifdef HAVE_JACK_SESSION
43 Session::jack_session_event (jack_session_event_t* event)
45 char timebuf[128], *tmp;
50 localtime_r (&n, &local_time);
51 strftime (timebuf, sizeof(timebuf), "JS_%FT%T", &local_time);
53 while ((tmp = strchr(timebuf, ':'))) { *tmp = '.'; }
55 if (event->type == JackSessionSaveTemplate)
57 if (save_template( timebuf )) {
58 event->flags = JackSessionSaveError;
60 string cmd ("ardour3 -P -U ");
61 cmd += event->client_uuid;
65 event->command_line = strdup (cmd.c_str());
70 if (save_state (timebuf)) {
71 event->flags = JackSessionSaveError;
73 std::string xml_path (_session_dir->root_path());
74 std::string legalized_filename = legalize_for_path (timebuf) + statefile_suffix;
75 xml_path = Glib::build_filename (xml_path, legalized_filename);
77 string cmd ("ardour3 -P -U ");
78 cmd += event->client_uuid;
83 event->command_line = strdup (cmd.c_str());
87 /* this won't be called if the port engine in use is not JACK, so we do
88 not have to worry about the type of PortEngine::private_handle()
91 jack_client_t* jack_client = (jack_client_t*) AudioEngine::instance()->port_engine().private_handle();
94 jack_session_reply (jack_client, event);
97 if (event->type == JackSessionSaveAndQuit) {
98 Quit (); /* EMIT SIGNAL */
101 jack_session_event_free( event );
106 Session::jack_timebase_callback (jack_transport_state_t /*state*/,
107 pframes_t /*nframes*/,
108 jack_position_t* pos,
109 int /*new_position*/)
111 Timecode::BBT_Time bbt;
117 TempoMetric metric (_tempo_map->metric_at (_transport_frame));
120 _tempo_map->bbt_time_rt (_transport_frame, bbt);
123 pos->beat = bbt.beats;
124 pos->tick = bbt.ticks;
126 // XXX still need to set bar_start_tick
128 pos->beats_per_bar = metric.meter().divisions_per_bar();
129 pos->beat_type = metric.meter().note_divisor();
130 pos->ticks_per_beat = Timecode::BBT_Time::ticks_per_beat;
131 pos->beats_per_minute = metric.tempo().beats_per_minute();
133 pos->valid = jack_position_bits_t (pos->valid | JackPositionBBT);
140 #ifdef HAVE_JACK_VIDEO_SUPPORT
141 //poke audio video ratio so Ardour can track Video Sync
142 pos->audio_frames_per_video_frame = frame_rate() / timecode_frames_per_second();
143 pos->valid = jack_position_bits_t (pos->valid | JackAudioVideoRatio);
149 pos->timecode_offset = config.get_timecode_offset();
150 t.timecode_frame_rate = timecode_frames_per_second();
151 pos->valid = jack_position_bits_t (pos->valid | JackPositionTimecode;
153 if (_transport_speed) {
157 Location* location = _locations.auto_loop_location();
161 t.transport_state = JackTransportLooping;
162 t.loop_start = location->start();
163 t.loop_end = location->end();
164 t.valid = jack_transport_bits_t (t.valid | JackTransportLoop);
170 t.transport_state = JackTransportRolling;
178 t.transport_state = JackTransportRolling;