summaryrefslogtreecommitdiff
path: root/libs/ardour/ardour/bundle.h
blob: f9971ddf155239c1107323e93c47b08de6bb1637 (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) 2002-2007 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.

*/

#ifndef __ardour_bundle_h__
#define __ardour_bundle_h__

#include <string>
#include <vector>
#include <glibmm/thread.h>
#include <sigc++/signal.h>
#include "ardour/data_type.h"

namespace ARDOUR {
  
/** A set of `channels', each of which is associated with 0 or more ports.
 *  Each channel has a name which can be anything useful.
 *  Intended for grouping things like, for example, a buss' outputs.
 *  `Channel' is a rather overloaded term but I can't think of a better
 *  one right now.
 */
class Bundle : public sigc::trackable
{
  public:

	/// List of ports associated with a channel.  We can't use a
	/// PortSet because we might want to involve non-Ardour ports
	/// (ie those without a Port object)
	typedef std::vector<std::string> PortList;

	struct Channel {
		Channel (std::string n) : name (n) {}

		bool operator== (Channel const &o) const {
			return name == o.name && ports == o.ports;
		}
		
		std::string name;
		PortList ports;
	};

	/** Construct an audio bundle.
	 *  @param i true if ports are inputs, otherwise false.
	 */
	Bundle (bool i = true) : _type (DataType::AUDIO), _ports_are_inputs (i) {}

	/** Construct an audio bundle.
	 *  @param n Name.
	 *  @param i true if ports are inputs, otherwise false.
	 */
	Bundle (std::string const & n, bool i = true) : _name (n), _type (DataType::AUDIO), _ports_are_inputs (i) {}

	/** Construct a bundle.
	 *  @param n Name.
	 *  @param t Type.
	 *  @param i true if ports are inputs, otherwise false.
	 */
	Bundle (std::string const & n, DataType t, bool i = true) : _name (n), _type (t), _ports_are_inputs (i) {}

	virtual ~Bundle() {}

	/** @return Number of channels that this Bundle has */
	uint32_t nchannels () const;

	/** @param Channel index.
	 *  @return Ports associated with this channel.
	 */
	PortList const & channel_ports (uint32_t) const;

	void add_channel (std::string const &);
	std::string channel_name (uint32_t) const;
	void set_channel_name (uint32_t, std::string const &);
	void add_port_to_channel (uint32_t, std::string);
	void set_port (uint32_t, std::string);
	void remove_port_from_channel (uint32_t, std::string);
	bool port_attached_to_channel (uint32_t, std::string);
	bool uses_port (std::string) const;
	bool offers_port_alone (std::string) const;
	void remove_channel (uint32_t);
	void remove_channels ();

	/** Set the name.
	 *  @param n New name.
	 */
	void set_name (std::string const & n) {
		_name = n;
		NameChanged ();
	}

	/** @return Bundle name */
	std::string name () const { return _name; }

	/** Set the type of the ports in this Bundle.
	 *  @param t New type.
	 */
	void set_type (DataType t) { _type = t; }

	/** @return Type of the ports in this Bundle. */
	DataType type () const { return _type; }

	void set_ports_are_inputs () { _ports_are_inputs = true; }
	void set_ports_are_outputs () { _ports_are_inputs = false; }
	bool ports_are_inputs () const { return _ports_are_inputs; }
	bool ports_are_outputs () const { return !_ports_are_inputs; }

	bool operator== (Bundle const &) const;

	/** Emitted when the bundle name or a channel name has changed */
	sigc::signal<void> NameChanged;
	/** The number of channels has changed */
	sigc::signal<void> ConfigurationChanged;
	/** The port list associated with one of our channels has changed */
	sigc::signal<void, int> PortsChanged;

  protected:
	
	/// mutex for _channel_ports and _channel_names
	/// XXX: is this necessary?
	mutable Glib::Mutex _channel_mutex;
	std::vector<Channel> _channel;

  private:
	int set_channels (std::string const &);
	int parse_io_string (std::string const &, std::vector<std::string> &);
	
	std::string _name;
	ARDOUR::DataType _type;
	bool _ports_are_inputs;
};

}

#endif /* __ardour_bundle_h__ */