Ardour  9.2-79-gba93f2fe52
bundle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2012 Carl Hetherington <carl@carlh.net>
3  * Copyright (C) 2008-2013 Paul Davis <paul@linuxaudiosystems.com>
4  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
5  * Copyright (C) 2017 Julien "_FrnchFrgg_" RIVAUD <frnchfrgg@free.fr>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #pragma once
23 
24 #include <memory>
25 #include <string>
26 #include <vector>
27 
28 #include "pbd/mutex.h"
29 #include "pbd/signals.h"
30 
31 #include "ardour/data_type.h"
32 #include "ardour/chan_count.h"
33 
34 namespace ARDOUR {
35 
36 class AudioEngine;
37 
45 {
46  public:
47 
51  typedef std::vector<std::string> PortList;
52 
53  struct Channel {
54  /* Constructor with no port name(s) */
55  Channel (std::string n, DataType t) : name (n), type (t) {}
56  /* Constructor with list of port names */
57  Channel (std::string n, DataType t, PortList p) : name (n), type (t), ports (p) {}
58  /* Constructor with a port name */
59  Channel (std::string n, DataType t, std::string const & p) : name (n), type (t) {
60  ports.push_back (p);
61  }
62 
63  bool operator== (Channel const &o) const {
64  return name == o.name && type == o.type && ports == o.ports;
65  }
66 
67  std::string name;
70  };
71 
72  Bundle (bool i = true);
73  Bundle (std::string const &, bool i = true);
74  Bundle (std::shared_ptr<Bundle>);
75 
76  virtual ~Bundle() {}
77 
79  ChanCount nchannels () const;
80  uint32_t n_total () const; /* shortcut for nchannels().n_total() */
81 
85  PortList const & channel_ports (uint32_t c) const;
86 
87  void add_channel (std::string const &, DataType);
88  void add_channel (std::string const &, DataType, std::string const &);
89  void add_channel (std::string const &, DataType, PortList);
90  std::string channel_name (uint32_t) const;
91  DataType channel_type (uint32_t) const;
92  void set_channel_name (uint32_t, std::string const &);
93  void add_port_to_channel (uint32_t, std::string);
94  void set_port (uint32_t, std::string);
95  void remove_port_from_channel (uint32_t, std::string);
96  void remove_ports_from_channel (uint32_t);
98  bool port_attached_to_channel (uint32_t, std::string);
99  bool offers_port (std::string) const;
100  bool offers_port_alone (std::string) const;
101  void remove_channel (uint32_t);
103  void add_channels_from_bundle (std::shared_ptr<Bundle>);
104  void connect (std::shared_ptr<Bundle>, AudioEngine &,
105  bool allow_partial = false);
106  void disconnect (std::shared_ptr<Bundle>, AudioEngine &);
107  bool connected_to (std::shared_ptr<Bundle>, AudioEngine &,
108  DataType type = DataType::NIL,
109  bool exclusive = false);
111  bool has_same_ports (std::shared_ptr<Bundle>) const;
112  uint32_t type_channel_to_overall (DataType, uint32_t) const;
113  uint32_t overall_channel_to_type (DataType, uint32_t) const;
114 
115  void set_name (std::string const &);
116 
118  std::string name () const { return _name; }
119 
122  bool ports_are_inputs () const { return _ports_are_inputs; }
123  bool ports_are_outputs () const { return !_ports_are_inputs; }
124 
126  void resume_signals ();
127 
128  bool operator== (Bundle const & other);
129 
131  enum Change {
132  NameChanged = 0x1,
133  ConfigurationChanged = 0x2,
134  PortsChanged = 0x4,
135  TypeChanged = 0x8,
136  DirectionChanged = 0x10
137  };
138 
140 
141  protected:
142 
146  std::vector<Channel> _channel;
147 
148  private:
149  int set_channels (std::string const &);
150  int parse_io_string (std::string const &, std::vector<std::string> &);
152 
153  std::string _name;
155 
158 };
159 
161 {
162 public:
163  BundleChannel () : channel (-1) {}
164 
165  BundleChannel (std::shared_ptr<Bundle> b, int c)
166  : bundle (b), channel (c) {}
167 
168  bool operator== (BundleChannel const& other) const {
169  return bundle == other.bundle && channel == other.channel;
170  }
171 
172  bool operator!= (BundleChannel const& other) const {
173  return bundle != other.bundle || channel != other.channel;
174  }
175 
176  ChanCount nchannels () const {
177  if (!_nchannels) {
178  _nchannels = bundle->nchannels ();
179  }
180  return _nchannels.value ();
181  }
182 
183  std::shared_ptr<Bundle> bundle;
184  int channel;
185 
186 private:
187  mutable std::optional<ChanCount> _nchannels;
188 };
189 
190 }
191 
192 std::ostream & operator<< (std::ostream & o, ARDOUR::Bundle const &);
193 
std::ostream & operator<<(std::ostream &o, ARDOUR::Bundle const &)
int channel
channel index, or -1 for "all"
Definition: bundle.h:184
std::shared_ptr< Bundle > bundle
Definition: bundle.h:183
ChanCount nchannels() const
Definition: bundle.h:176
BundleChannel(std::shared_ptr< Bundle > b, int c)
Definition: bundle.h:165
std::optional< ChanCount > _nchannels
Definition: bundle.h:187
std::string channel_name(uint32_t) const
ChanCount nchannels() const
void add_port_to_channel(uint32_t, std::string)
void remove_ports_from_channel(uint32_t)
void add_channels_from_bundle(std::shared_ptr< Bundle >)
void set_channel_name(uint32_t, std::string const &)
std::string _name
Definition: bundle.h:153
void disconnect(std::shared_ptr< Bundle >, AudioEngine &)
void resume_signals()
void suspend_signals()
bool offers_port(std::string) const
bool ports_are_inputs() const
Definition: bundle.h:122
bool has_same_ports(std::shared_ptr< Bundle >) const
void add_channel(std::string const &, DataType, PortList)
void set_port(uint32_t, std::string)
std::vector< Channel > _channel
Definition: bundle.h:146
bool _ports_are_inputs
Definition: bundle.h:154
bool _signals_suspended
Definition: bundle.h:156
bool offers_port_alone(std::string) const
void remove_channels()
int set_channels(std::string const &)
bool ports_are_outputs() const
Definition: bundle.h:123
bool port_attached_to_channel(uint32_t, std::string)
Bundle(std::shared_ptr< Bundle >)
std::string name() const
Definition: bundle.h:118
uint32_t type_channel_to_overall(DataType, uint32_t) const
PBD::Mutex _channel_mutex
Definition: bundle.h:145
uint32_t n_total() const
PortList const & channel_ports(uint32_t c) const
void add_channel(std::string const &, DataType, std::string const &)
void remove_channel(uint32_t)
void emit_changed(Change)
Bundle(std::string const &, bool i=true)
void add_channel(std::string const &, DataType)
std::vector< std::string > PortList
Definition: bundle.h:51
void remove_ports_from_channels()
void set_ports_are_inputs()
void set_ports_are_outputs()
void connect(std::shared_ptr< Bundle >, AudioEngine &, bool allow_partial=false)
void set_name(std::string const &)
void remove_port_from_channel(uint32_t, std::string)
Bundle(bool i=true)
PBD::Signal< void(Change)> Changed
Definition: bundle.h:139
bool connected_to(std::shared_ptr< Bundle >, AudioEngine &, DataType type=DataType::NIL, bool exclusive=false)
uint32_t overall_channel_to_type(DataType, uint32_t) const
DataType channel_type(uint32_t) const
bool connected_to_anything(AudioEngine &)
Change _pending_change
Definition: bundle.h:157
virtual ~Bundle()
Definition: bundle.h:76
int parse_io_string(std::string const &, std::vector< std::string > &)
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
DebugBits AudioEngine
Definition: session.h:1416
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
std::string name
Definition: bundle.h:67
Channel(std::string n, DataType t, std::string const &p)
Definition: bundle.h:59
Channel(std::string n, DataType t, PortList p)
Definition: bundle.h:57
Channel(std::string n, DataType t)
Definition: bundle.h:55