summaryrefslogtreecommitdiff
path: root/libs/ardour/engine_slave.cc
blob: 37f128ef03a78547fe642b8ee38512162ccabf1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (C) 2013-2019 Paul Davis <paul@linuxaudiosystems.com>
 * Copyright (C) 2015-2018 Robin Gareus <robin@gareus.org>
 *
 * 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.
 */

#include <iostream>
#include <cerrno>

#include "ardour/audioengine.h"
#include "ardour/audio_backend.h"
#include "ardour/session.h"
#include "ardour/transport_master.h"

#include "pbd/i18n.h"

using namespace std;
using namespace ARDOUR;

Engine_TransportMaster::Engine_TransportMaster (AudioEngine& e)
	: TransportMaster (Engine, X_("JACK"))
	, engine (e)
	, _starting (false)
{
	check_backend ();
}

Engine_TransportMaster::~Engine_TransportMaster ()
{
}

void
Engine_TransportMaster::init ()
{
}

bool
Engine_TransportMaster::usable () const
{
	return AudioEngine::instance()->current_backend_name() == X_("JACK");
}

void
Engine_TransportMaster::check_backend()
{
	if (AudioEngine::instance()->current_backend_name() == X_("JACK")) {
		_connected = true;
	} else {
		_connected = false;
	}
}

void
Engine_TransportMaster::reset (bool)
{
	_starting = false;
}

bool
Engine_TransportMaster::locked() const
{
	return true;
}

bool
Engine_TransportMaster::ok() const
{
	return true;
}

void
Engine_TransportMaster::pre_process (pframes_t, samplepos_t, boost::optional<samplepos_t>)
{
	/* nothing to do */
}

bool
Engine_TransportMaster::speed_and_position (double& sp, samplepos_t& position, samplepos_t& lp, samplepos_t & when, samplepos_t now)
{
	boost::shared_ptr<AudioBackend> backend = engine.current_backend();

	/* 3rd argument (now) doesn't matter here because we're always being
	 * called synchronously with the engine.
	 */

	if (backend) {
		_starting = backend->speed_and_position (sp, position);
	} else {
		_starting = false;
	}

	lp = now;
	when = now;

	_current_delta = 0;

	return true;
}

std::string
Engine_TransportMaster::position_string () const
{
	if (_session) {
		return PBD::to_string (_session->audible_sample());
	}

	return std::string();
}

std::string
Engine_TransportMaster::delta_string () const
{
	return string ("\u0394     0  ");
}

bool
Engine_TransportMaster::allow_request (TransportRequestSource src, TransportRequestType type) const
{
	if (_session) {
		if (_session->config.get_jack_time_master()) {
			return true;
		} else {
			return false;
		}
	}

	return true;
}

samplecnt_t
Engine_TransportMaster::update_interval () const
{
	return AudioEngine::instance()->samples_per_cycle();
}