libAlgAudio  v1.99-440-g08538e5-dirty
The development library for AlgAudio framework.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Canvas.hpp
Go to the documentation of this file.
1 #ifndef CANVAS_HPP
2 #define CANVAS_HPP
3 /*
4 This file is part of AlgAudio.
5 
6 AlgAudio, Copyright (C) 2015 CeTA - Audiovisual Technology Center
7 
8 AlgAudio is free software: you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as
10 published by the Free Software Foundation, either version 3 of the
11 License, or (at your option) any later version.
12 
13 AlgAudio is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
17 
18 You should have received a copy of the GNU Lesser General Public License
19 along with AlgAudio. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include <memory>
23 #include <set>
24 #include "Module.hpp"
25 #include "Utilities.hpp"
26 
27 namespace AlgAudio{
28 
29 namespace Exceptions{
31  MultipleConnections(std::string t) : Exception(t) {}
32 };
33 struct ConnectionLoop : public Exception{
34  ConnectionLoop(std::string t) : Exception(t) {}
35 };
36 struct DoubleConnection : public Exception{
37  DoubleConnection(std::string t) : Exception(t) {}
38 };
39 } // namespace Exceptions
40 
51 class Canvas : public std::enable_shared_from_this<Canvas>{
52 public:
57  static LateReturn<std::shared_ptr<Canvas>> CreateEmpty(std::shared_ptr<Canvas> parent);
58 
59  virtual ~Canvas();
60 
63  std::shared_ptr<Group> GetGroup() const {return group;}
64 
72  void RemoveModule(std::shared_ptr<Module>);
73 
75  std::set<std::shared_ptr<Module>> modules;
76 
79  std::shared_ptr<Module> owner_hint = nullptr;
80 
85  struct IOID{
86  std::shared_ptr<Module> module;
87  std::string iolet;
88  bool operator<(const IOID& other) const {return (module==other.module)?(iolet<other.iolet):(module<other.module);}
89  bool operator==(const IOID& other) const {return (module==other.module)?(iolet==other.iolet):false;}
90  };
92  std::shared_ptr<Module::Inlet > GetInletByIOID(IOID) const;
94  std::shared_ptr<Module::Outlet> GetOutletByIOID(IOID) const;
95 
96  // === AUDIO CONNECTIONS ====
97 
99  void Connect(IOID from, IOID to);
101  bool GetDirectAudioConnectionExists(IOID from, IOID to);
103  void Disconnect(IOID from, IOID to);
104 
107  bool TestNewConnectionForLoop(IOID from, IOID to);
110  std::list<std::shared_ptr<Module>> GetConnectedModules(std::shared_ptr<Module> m);
111 
115  void RecalculateOrder();
122  void BlockReordering(bool enable);
123 
124  /*The list of all audio connections "from-to", in the format of one-to-many. */
125  std::map<IOID, std::list<IOID>> audio_connections;
126 
127  // === DATA CONNECTIONS ====
128 
129  enum class DataConnectionMode{
134  Relative,
138  Absolute
139  };
140 
142  void ConnectData(IOID from, IOID to, DataConnectionMode m);
145  std::pair<bool, DataConnectionMode> GetDirectDataConnectionExists(IOID from, IOID to);
147  void DisconnectData(IOID from, IOID to);
148 
149  struct IOIDWithMode{
152  bool operator==(const IOIDWithMode& other) const {return ioid == other.ioid; /* Ignore modes for comparison. */}
153  };
155  std::map<IOID, std::list<IOIDWithMode>> data_connections;
156 
157 private:
159  Canvas();
160 
162  std::shared_ptr<Group> group;
163 
165  std::weak_ptr<Canvas> parent;
166 
168  std::map<IOID, Subscription> data_connections_subscriptions;
171  void PassData(IOID source, float value, float relative);
173  bool do_not_recalculate_ordering;
174 };
175 
176 } // namespace AlgAudio
177 
178 #endif //CANVAS_HPP
void DisconnectData(IOID from, IOID to)
void Connect(IOID from, IOID to)
Definition: Canvas.hpp:51
DataConnectionMode mode
Definition: Canvas.hpp:151
MultipleConnections(std::string t)
Definition: Canvas.hpp:31
std::shared_ptr< Group > GetGroup() const
Definition: Canvas.hpp:63
std::pair< bool, DataConnectionMode > GetDirectDataConnectionExists(IOID from, IOID to)
std::map< IOID, std::list< IOIDWithMode > > data_connections
Definition: Canvas.hpp:155
DataConnectionMode
Definition: Canvas.hpp:129
ConnectionLoop(std::string t)
Definition: Canvas.hpp:34
void RecalculateOrder()
bool TestNewConnectionForLoop(IOID from, IOID to)
virtual ~Canvas()
std::set< std::shared_ptr< Module > > modules
Definition: Canvas.hpp:75
DoubleConnection(std::string t)
Definition: Canvas.hpp:37
Definition: Canvas.hpp:85
std::shared_ptr< Module::Inlet > GetInletByIOID(IOID) const
LateReturn< std::shared_ptr< Module > > CreateModule(std::string id)
std::list< std::shared_ptr< Module > > GetConnectedModules(std::shared_ptr< Module > m)
Definition: Alertable.hpp:26
Definition: Canvas.hpp:149
std::map< IOID, std::list< IOID > > audio_connections
Definition: Canvas.hpp:125
bool operator==(const IOIDWithMode &other) const
Definition: Canvas.hpp:152
IOID ioid
Definition: Canvas.hpp:150
std::shared_ptr< Module::Outlet > GetOutletByIOID(IOID) const
void Disconnect(IOID from, IOID to)
void ConnectData(IOID from, IOID to, DataConnectionMode m)
bool operator<(const IOID &other) const
Definition: Canvas.hpp:88
std::shared_ptr< Module > owner_hint
Definition: Canvas.hpp:79
void BlockReordering(bool enable)
Definition: LateReturn.hpp:35
std::string iolet
Definition: Canvas.hpp:87
bool operator==(const IOID &other) const
Definition: Canvas.hpp:89
Definition: Exception.hpp:29
static LateReturn< std::shared_ptr< Canvas > > CreateEmpty(std::shared_ptr< Canvas > parent)
bool GetDirectAudioConnectionExists(IOID from, IOID to)
void RemoveModule(std::shared_ptr< Module >)
std::shared_ptr< Module > module
Definition: Canvas.hpp:86
Definition: Canvas.hpp:33