SPAOP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SourceController.h
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Martin Hansen
3  *
4  * This file is part of SPAOP (Spatial Audio Object Positioner).
5  *
6  * SPAOP is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * SPAOP is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with SPAOP. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef SOURCECONTROLLER_H_INCLUDED
21 #define SOURCECONTROLLER_H_INCLUDED
22 
23 #include <memory>
24 
25 #include "SourceCollection.h"
26 #include "WonderHeader.h"
27 #include "ConnectionTimer.h"
28 #include "VisualStreamReceiver.h"
29 #include "OscSender.h"
30 #include "PingControl.h"
31 #include "XmlParser.h"
32 #include "Parsetools.h"
33 
34 #define ABS(x) ((x) > 0 ? (x) : -(x))
35 
36 namespace wonder {
37 
45 {
46 public:
47 
51  class Listener
52  {
53  public:
55  virtual ~Listener() {}
56 
61  float newValue) = 0;
62 
72  virtual void incomingMaxNoSources(const int maxSources){}
73 
75  virtual void connectionLost () {}
76  };
77 
99  Listener* listener,
100  ConnectionTimer::Factory* timerFactory,
101  XmlParser* xmlParser,
102  int maxSources);
103 
105  virtual ~SourceController();
106 
111  const Source& getSource() const;
112 
119  std::shared_ptr<const SourceCollection> getSources() const;
120 
137  bool setSource(const Source &source);
138 
148  bool setID(int sourceID);
149 
162  void setParameterAndSendChange (int paramIndex, float normalizedValue);
163 
178  void setCoordinatesAndSendChange (float normalizedX, float normalizedY);
179 
186  void updateSourceName(const std::string& newSourceName);
187 
194  void updateSourceColour(const Colour colour);
195 
208  void setLinkedToWonder(bool linked, bool notifyPeers = true);
209 
216  bool isLinkedToWonder() const;
217 
227  bool setCWonderAddress(const std::string &ip, const std::string &port);
228 
234  std::string getCWonderHost() const;
235 
241  std::string getCWonderPort() const;
242 
253  void setIdIsLocked(bool isLocked);
254 
256  bool idIsLocked() const;
257 
267 
275  std::string connectionStatusString() const;
276 
281  int rcvPort() const;
282 
290  const std::string getDataDestHostAndPort() const;
291 
297  std::shared_ptr<const Room> getRoom() const;
298 
304  void setRoom(const Room& room);
305 
306 private:
307  SourceController(const SourceController& other); // copying not allowed
308  SourceController &operator= (const SourceController other); // assignment not allowed
309 
310  std::unique_ptr<VisualStreamReceiver> server_;
311  std::unique_ptr<OscSenderThread> cWonder_; // cWONDER
312  std::unique_ptr<OscSenderThread> mCaster_; // the StreamMulticaster
313  std::unique_ptr<OscSenderThread> peerGroup_; // the multicast group
314 
315  XmlParser* xmlParser_;
316  std::shared_ptr<SourceCollection> sources_; // object might be share with a GUI
317  // that might be destructed after
318  // this object -> shared_ptr
319  int sourceID_;
320  std::shared_ptr<Room> room_;
321  Listener* listener_;
322  PingControl pingControl_;
323  bool linkedToWonder_; // is sending outgoing OSC messages to WONDER
324  bool isLocked_;
325  ConnectionStates cStatus_;
326  float lastValues_[Source::totalNumParams]; // the last values of automated parameters
327  // that were sent out (denormalized!)
328 
332  void setIncomingParameter (int sourceID, Source::AutomatedParameters index,
333  float unnormalizedValue);
334 
343  bool relevantChange(int index);
344 
349  OscSenderThread& dataDest() const;
350 
355  OscSenderThread& streamSource() const;
356 
361  void sendOwnState();
362 
363  //==============================================================================
364  //vvvvv Implementing ConnectionTimer::Listener
365 
366  void onTimeout();
367 
368  //==============================================================================
369  //vvvvv Implementing PingControl::Listener
370 
371  void connectionLost(const int connectionID);
372 
373  //==============================================================================
374  //vvvvv OSC-message-handlers implementing wonder::VisualStreamReceiver::Listener
375 
376  int onSourceActivate(int wondID);
377 
378  int onSourceDeactivate(int wondID);
379 
380  int onSourcePosition(int wondID, float xPos, float yPos);
381 
382  int onSourceAngle(int wondID, float angle);
383 
384  int onSourceType(int wondID, int type);
385 
386  int onSourceName(int wondID, const std::string& sourceName);
387 
388  int onSourceColor(int wondID, int r, int g, int b);
389 
390  int onSourceGroupId(int wondID, int groupID)
391  { return 0; }
392 
393  int onSourceRotatingDirection(int wondID, int rotDir)
394  { return 0; }
395 
396  int onSourceScalingDirection(int wondID, int scalDir)
397  { return 0; }
398 
399  int onSourceDopplerEffect(int wondID, int doppler);
400 
401  int onListenerPosition(int listenerID, float x, float y)
402  { return 0; }
403 
404  int onGlobalMaxNoSources(int maxSources);
405 
406  int onGlobalRenderpolygon(Room& room);
407 
408  int onProjectXmlDump(int err, const std::string& xmlDump);
409 
410  int onStreamVisualPing(int pingCount, OscSender* replyTo);
411 
412  int onStreamVisualPong(int pingCount){ return 0; }
413 
414  int onStreamVisualConnect(OscSender* replyTo);
415 
416  int onReply(std::string replyToMsg, int state, std::string msg);
417 
418  int onPluginStandalone(bool standAloneOn);
419 
420 };
421 
422 }
423 
424 
425 #endif // SOURCECONTROLLER_H_INCLUDED
std::string connectionStatusString() const
Returns a string representation of the current status of the incoming "Visual Stream" connection...
Definition: SourceController.cpp:285
void setCoordinatesAndSendChange(float normalizedX, float normalizedY)
Sets the coordinates of the source that is controlled by this SourceController and sends them to cWON...
Definition: SourceController.cpp:159
Another listener interface especially for incoming ping messages.
Definition: VisualStreamReceiver.h:258
A factory class that creates VisualStreamReceiver instances.
Definition: VisualStreamReceiver.h:318
A listener interface that can be registered with the VisualStreamReceiver.
Definition: VisualStreamReceiver.h:64
std::string getCWonderHost() const
Returns the IP or hostname that is set for cWONDER.
Definition: SourceController.cpp:249
virtual void connectionLost()
Called when the (incoming data) connection is lost.
Definition: SourceController.h:75
const std::string getDataDestHostAndPort() const
Returns the Address where the WONDER control message are sent to.
Definition: SourceController.cpp:301
bool setCWonderAddress(const std::string &ip, const std::string &port)
Sets the address where outgoing OSC messages will be sent in "linked to WONDER" mode will be sent (i...
Definition: SourceController.cpp:239
ConnectionStates
An enum describing the differents states of an incoming connection.
Definition: WonderHeader.h:134
A class for connection timeout control.
Definition: PingControl.h:36
ConnectionStates connectionStatus() const
Returns the current status of the incoming connection.
Definition: SourceController.cpp:280
bool idIsLocked() const
Returns true if the source ID is locked.
Definition: SourceController.cpp:275
void setIdIsLocked(bool isLocked)
Sets the ID locked status.
Definition: SourceController.cpp:259
An interface for a thread implementing the OscSender interface.
Definition: OscSenderThread.h:38
A struct representing a (RGB) colour.
Definition: Colours.h:28
int rcvPort() const
Returns the port this instance is listening on.
Definition: SourceController.cpp:296
An interface for a factory class that creates ConnectionTimers.
Definition: ConnectionTimer.h:72
bool setID(int sourceID)
Sets the ID of the source that is controlled by this SourceController.
Definition: SourceController.cpp:108
AutomatedParameters
Parameters that can be automated by the host must be accessed using this enum.
Definition: Source.h:81
void setLinkedToWonder(bool linked, bool notifyPeers=true)
Sets whether this SourceController shall communicate with WONDER ("linked to wonder") or not...
Definition: SourceController.cpp:193
virtual ~Listener()
Destructor.
Definition: SourceController.h:55
A class containing the wonder-specific information about a room (name and vertices).
Definition: Room.h:35
void updateSourceName(const std::string &newSourceName)
Updates the name of the source that is controlled by this SourceController and sends out the correspo...
Definition: SourceController.cpp:177
SourceController(VisualStreamReceiver::Factory *vsFactory, Listener *listener, ConnectionTimer::Factory *timerFactory, XmlParser *xmlParser, int maxSources)
Constructor.
Definition: SourceController.cpp:24
An interface for a listener that listens to various callbacks triggered by incoming messages or conne...
Definition: SourceController.h:51
bool setSource(const Source &source)
Copies the parameters of a given Source object to the internal SourceCollection (overwriting the Sour...
Definition: SourceController.cpp:96
void updateSourceColour(const Colour colour)
Updates the colour of the source that is controlled by this SourceController and sends out the corres...
Definition: SourceController.cpp:185
void setParameterAndSendChange(int paramIndex, float normalizedValue)
Sets a parameter of the source that is controlled by this SourceController and sends it to cWONDER (i...
Definition: SourceController.cpp:118
virtual ~SourceController()
Destructor.
Definition: SourceController.cpp:63
std::string getCWonderPort() const
Returns the port that is set for cWONDER.
Definition: SourceController.cpp:254
void setRoom(const Room &room)
Sets the internal Room object to the parameters of a given Room object.
Definition: SourceController.cpp:311
A class for objects representing a WONDER source with all its properties.
Definition: Source.h:60
virtual void incomingParameterChange(Source::AutomatedParameters index, float newValue)=0
Called when one of the sources automatable parameters is changed by an incoming message.
bool isLinkedToWonder() const
Returns the linkedToWonder status.
Definition: SourceController.cpp:234
std::shared_ptr< const SourceCollection > getSources() const
Returns a (reference-counting) shared pointer to the SourceCollection object that is controlled by th...
Definition: SourceController.cpp:91
std::shared_ptr< const Room > getRoom() const
Returns a (reference-counting) shared pointer to the Room object stored internally.
Definition: SourceController.cpp:306
The main communication node that keeps track of all virtual sources and enables the host DAW to contr...
Definition: SourceController.h:42
A listener class for callbacks in case loss of connection is detected.
Definition: PingControl.h:44
const Source & getSource() const
Returns the Source object that is controlled by this SourceController.
Definition: SourceController.cpp:86
An interface defining a class that sets the parameters of one or several sources from an XML formatte...
Definition: XmlParser.h:30
Total number of (automated) parameters.
Definition: Source.h:89
virtual void incomingMaxNoSources(const int maxSources)
Called when the maximum number of sources allowed by the WONDER system has been received via the /glo...
Definition: SourceController.h:72