summaryrefslogtreecommitdiff
path: root/libs/ardour/jack_port.cc
blob: 221e46b076ad1d9551565ea447bf4eabedabeec1 (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
/*
    Copyright (C) 2002-2006 Paul Davis 

    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., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include <pbd/error.h>

#include <ardour/jack_port.h>
#include <ardour/audioengine.h>

#include "i18n.h"

using namespace ARDOUR;
using namespace PBD;
using namespace std;

AudioEngine* JackPort::engine = 0;

JackPort::JackPort (const std::string& name, DataType type, Flags flgs) 
	: _port (0)
{
	_port = jack_port_register (engine->jack(), name.c_str(), type.to_jack_type(), flgs, 0);

	if (_port == 0) {
		throw failed_constructor();
	}
	
	_flags = flgs;
	_type  = type;
	_name = jack_port_name (_port);
}

JackPort::~JackPort ()
{
	cerr << "deleting jack port " << _name << endl;

	jack_port_unregister (engine->jack(), _port);
}

int 
JackPort::set_name (string str)
{
	int ret;

	if ((ret = jack_port_set_name (_port, str.c_str())) == 0) {
		_name = str;
	}
	
	return ret;
}

int
JackPort::disconnect ()
{
	return jack_port_disconnect (engine->jack(), _port);
}	

void
JackPort::set_engine (AudioEngine* e)
{
	engine = e;
}

nframes_t
JackPort::total_latency () const
{
	return jack_port_get_total_latency (engine->jack(), _port);
}

int
JackPort::reestablish ()
{
	string short_name;
	
	short_name = _name.substr (_name.find_last_of (':') + 1);

	_port = jack_port_register (engine->jack(), short_name.c_str(), type().to_jack_type(), _flags, 0);

	if (_port == 0) {
		error << string_compose (_("could not reregister %1"), _name) << endmsg;
		return -1;
	}

	reset ();
	

	return 0;
}

void
JackPort::recompute_total_latency () const
{
#ifdef HAVE_JACK_RECOMPUTE_LATENCY
	jack_recompute_total_latency (engine->jack(), _port);
#endif
}