Ardour  9.0-pre0-582-g084a23a80d
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 <glibmm/threads.h>
29 
30 #include "pbd/signals.h"
31 
32 #include "ardour/data_type.h"
33 #include "ardour/chan_count.h"
34 
35 namespace ARDOUR {
36 
37 class AudioEngine;
38 
46 {
47  public:
48 
52  typedef std::vector<std::string> PortList;
53 
54  struct Channel {
55  /* Constructor with no port name(s) */
56  Channel (std::string n, DataType t) : name (n), type (t) {}
57  /* Constructor with list of port names */
58  Channel (std::string n, DataType t, PortList p) : name (n), type (t), ports (p) {}
59  /* Constructor with a port name */
60  Channel (std::string n, DataType t, std::string const & p) : name (n), type (t) {
61  ports.push_back (p);
62  }
63 
64  bool operator== (Channel const &o) const {
65  return name == o.name && type == o.type && ports == o.ports;
66  }
67 
68  std::string name;
71  };
72 
73  Bundle (bool i = true);
74  Bundle (std::string const &, bool i = true);
75  Bundle (std::shared_ptr<Bundle>);
76 
77  virtual ~Bundle() {}
78 
80  ChanCount nchannels () const;
81  uint32_t n_total () const; /* shortcut for nchannels().n_total() */
82 
86  PortList const & channel_ports (uint32_t c) const;
87 
88  void add_channel (std::string const &, DataType);
89  void add_channel (std::string const &, DataType, std::string const &);
90  void add_channel (std::string const &, DataType, PortList);
91  std::string channel_name (uint32_t) const;
92  DataType channel_type (uint32_t) const;
93  void set_channel_name (uint32_t, std::string const &);
94  void add_port_to_channel (uint32_t, std::string);
95  void set_port (uint32_t, std::string);
96  void remove_port_from_channel (uint32_t, std::string);
97  void remove_ports_from_channel (uint32_t);
99  bool port_attached_to_channel (uint32_t, std::string);
100  bool offers_port (std::string) const;
101  bool offers_port_alone (std::string) const;
102  void remove_channel (uint32_t);
104  void add_channels_from_bundle (std::shared_ptr<Bundle>);
105  void connect (std::shared_ptr<Bundle>, AudioEngine &,
106  bool allow_partial = false);
107  void disconnect (std::shared_ptr<Bundle>, AudioEngine &);
108  bool connected_to (std::shared_ptr<Bundle>, AudioEngine &,
109  DataType type = DataType::NIL,
110  bool exclusive = false);
112  bool has_same_ports (std::shared_ptr<Bundle>) const;
113  uint32_t type_channel_to_overall (DataType, uint32_t) const;
114  uint32_t overall_channel_to_type (DataType, uint32_t) const;
115 
116  void set_name (std::string const &);
117 
119  std::string name () const { return _name; }
120 
123  bool ports_are_inputs () const { return _ports_are_inputs; }
124  bool ports_are_outputs () const { return !_ports_are_inputs; }
125 
127  void resume_signals ();
128 
129  bool operator== (Bundle const & other);
130 
132  enum Change {
133  NameChanged = 0x1,
134  ConfigurationChanged = 0x2,
135  PortsChanged = 0x4,
136  TypeChanged = 0x8,
137  DirectionChanged = 0x10
138  };
139 
141 
142  protected:
143 
146  mutable Glib::Threads::Mutex _channel_mutex;
147  std::vector<Channel> _channel;
148 
149  private:
150  int set_channels (std::string const &);
151  int parse_io_string (std::string const &, std::vector<std::string> &);
153 
154  std::string _name;
156 
159 };
160 
162 {
163 public:
164  BundleChannel () : channel (-1) {}
165 
166  BundleChannel (std::shared_ptr<Bundle> b, int c)
167  : bundle (b), channel (c) {}
168 
169  bool operator== (BundleChannel const& other) const {
170  return bundle == other.bundle && channel == other.channel;
171  }
172 
173  bool operator!= (BundleChannel const& other) const {
174  return bundle != other.bundle || channel != other.channel;
175  }
176 
177  std::shared_ptr<Bundle> bundle;
178  int channel;
179 };
180 
181 }
182 
183 std::ostream & operator<< (std::ostream & o, ARDOUR::Bundle const &);
184 
std::ostream & operator<<(std::ostream &o, ARDOUR::Bundle const &)
int channel
channel index, or -1 for "all"
Definition: bundle.h:178
std::shared_ptr< Bundle > bundle
Definition: bundle.h:177
BundleChannel(std::shared_ptr< Bundle > b, int c)
Definition: bundle.h:166
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:154
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:123
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:147
bool _ports_are_inputs
Definition: bundle.h:155
bool _signals_suspended
Definition: bundle.h:157
bool offers_port_alone(std::string) const
void remove_channels()
int set_channels(std::string const &)
bool ports_are_outputs() const
Definition: bundle.h:124
bool port_attached_to_channel(uint32_t, std::string)
Bundle(std::shared_ptr< Bundle >)
std::string name() const
Definition: bundle.h:119
uint32_t type_channel_to_overall(DataType, uint32_t) const
Glib::Threads::Mutex _channel_mutex
Definition: bundle.h:146
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:52
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:140
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:158
virtual ~Bundle()
Definition: bundle.h:77
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:1349
bool operator==(const ProcessorSelection &a, const ProcessorSelection &b)
std::string name
Definition: bundle.h:68
Channel(std::string n, DataType t, std::string const &p)
Definition: bundle.h:60
Channel(std::string n, DataType t, PortList p)
Definition: bundle.h:58
Channel(std::string n, DataType t)
Definition: bundle.h:56