NO-OP: Re-indent websockets code

"Always use Tabstops for block-indent (the code must be
formatted correctly with "[TAB] = N spaces" for any value of N).
Use space only for alignment." - https://ardour.org/styleguide.html
This commit is contained in:
Robin Gareus 2020-02-23 16:03:59 +01:00
parent 224be91211
commit 5e3480ba8f
No known key found for this signature in database
GPG key ID: A090BCE02CF57F04
23 changed files with 1260 additions and 1217 deletions

View file

@ -105,7 +105,7 @@ ArdourWebsockets::do_request (ArdourWebsocketsUIRequest* req)
int int
ArdourWebsockets::start () ArdourWebsockets::start ()
{ {
// startup the event loop thread /* startup the event loop thread */
BaseUI::run (); BaseUI::run ();
for (std::vector<SurfaceComponent*>::iterator it = _components.begin (); for (std::vector<SurfaceComponent*>::iterator it = _components.begin ();
@ -122,7 +122,8 @@ ArdourWebsockets::start ()
} }
int int
ArdourWebsockets::stop () { ArdourWebsockets::stop ()
{
for (std::vector<SurfaceComponent*>::iterator it = _components.begin (); for (std::vector<SurfaceComponent*>::iterator it = _components.begin ();
it != _components.end (); ++it) { it != _components.end (); ++it) {
(*it)->stop (); (*it)->stop ();

View file

@ -33,17 +33,17 @@
#include "control_protocol/control_protocol.h" #include "control_protocol/control_protocol.h"
#include "component.h" #include "component.h"
#include "strips.h" #include "dispatcher.h"
#include "feedback.h"
#include "globals.h" #include "globals.h"
#include "server.h" #include "server.h"
#include "feedback.h" #include "strips.h"
#include "dispatcher.h"
#define SURFACE_NAME "WebSockets Server (Experimental)" #define SURFACE_NAME "WebSockets Server (Experimental)"
#define SURFACE_ID "uri://ardour.org/surfaces/ardour_websockets:0" #define SURFACE_ID "uri://ardour.org/surfaces/ardour_websockets:0"
namespace ArdourSurface { namespace ArdourSurface
{
struct ArdourWebsocketsUIRequest : public BaseUI::BaseRequestObject { struct ArdourWebsocketsUIRequest : public BaseUI::BaseRequestObject {
public: public:
ArdourWebsocketsUIRequest () {} ArdourWebsocketsUIRequest () {}
@ -54,7 +54,6 @@ class ArdourWebsockets : public ARDOUR::ControlProtocol,
public AbstractUI<ArdourWebsocketsUIRequest> public AbstractUI<ArdourWebsocketsUIRequest>
{ {
public: public:
ArdourWebsockets (ARDOUR::Session&); ArdourWebsockets (ARDOUR::Session&);
virtual ~ArdourWebsockets (); virtual ~ArdourWebsockets ();
@ -62,25 +61,38 @@ class ArdourWebsockets : public ARDOUR::ControlProtocol,
int set_active (bool); int set_active (bool);
ARDOUR::Session& ardour_session () { return *session; } ARDOUR::Session& ardour_session ()
ArdourStrips& strips_component () { return _strips; } {
ArdourGlobals& globals_component () { return _globals; } return *session;
WebsocketsServer& server_component () { return _server; } }
WebsocketsDispatcher& dispatcher_component () { return _dispatcher; } ArdourStrips& strips_component ()
{
return _strips;
}
ArdourGlobals& globals_component ()
{
return _globals;
}
WebsocketsServer& server_component ()
{
return _server;
}
WebsocketsDispatcher& dispatcher_component ()
{
return _dispatcher;
}
// ControlProtocol /* ControlProtocol */
void stripable_selection_changed () {} void stripable_selection_changed () {}
protected: protected:
/* BaseUI */
// BaseUI
void thread_init (); void thread_init ();
// AbstractUI /* AbstractUI */
void do_request (ArdourWebsocketsUIRequest*); void do_request (ArdourWebsocketsUIRequest*);
private: private:
ArdourStrips _strips; ArdourStrips _strips;
ArdourGlobals _globals; ArdourGlobals _globals;
ArdourFeedback _feedback; ArdourFeedback _feedback;
@ -90,9 +102,8 @@ class ArdourWebsockets : public ARDOUR::ControlProtocol,
int start (); int start ();
int stop (); int stop ();
}; };
} // namespace } // namespace ArdourSurface
#endif // ardour_websockets_h #endif // ardour_websockets_h

View file

@ -22,8 +22,8 @@
#include <boost/unordered_set.hpp> #include <boost/unordered_set.hpp>
#include <list> #include <list>
#include "state.h"
#include "message.h" #include "message.h"
#include "state.h"
typedef struct lws* Client; typedef struct lws* Client;
typedef std::list<NodeStateMessage> ClientOutputBuffer; typedef std::list<NodeStateMessage> ClientOutputBuffer;
@ -31,28 +31,32 @@ typedef std::list<NodeStateMessage> ClientOutputBuffer;
class ClientContext class ClientContext
{ {
public: public:
ClientContext (Client wsi)
ClientContext (Client wsi) : _wsi(wsi) {}; : _wsi (wsi){};
virtual ~ClientContext (){}; virtual ~ClientContext (){};
Client wsi () const { return _wsi; } Client wsi () const
{
return _wsi;
}
bool has_state (const NodeState&); bool has_state (const NodeState&);
void update_state (const NodeState&); void update_state (const NodeState&);
ClientOutputBuffer& output_buf () { return _output_buf; } ClientOutputBuffer& output_buf ()
{
return _output_buf;
}
std::string debug_str (); std::string debug_str ();
private: private:
Client _wsi; Client _wsi;
typedef boost::unordered_set<NodeState> ClientState; typedef boost::unordered_set<NodeState> ClientState;
ClientState _state; ClientState _state;
ClientOutputBuffer _output_buf; ClientOutputBuffer _output_buf;
}; };
#endif // client_context_h #endif // client_context_h

View file

@ -24,7 +24,8 @@
#include "ardour/session.h" #include "ardour/session.h"
#include "pbd/event_loop.h" #include "pbd/event_loop.h"
namespace ArdourSurface { namespace ArdourSurface
{
class ArdourWebsockets; class ArdourWebsockets;
} }
@ -36,13 +37,19 @@ class WebsocketsDispatcher;
class SurfaceComponent class SurfaceComponent
{ {
public: public:
SurfaceComponent (ArdourSurface::ArdourWebsockets& surface)
SurfaceComponent (ArdourSurface::ArdourWebsockets& surface) : _surface (surface) {}; : _surface (surface){};
virtual ~SurfaceComponent (){}; virtual ~SurfaceComponent (){};
virtual int start () { return 0; } virtual int start ()
virtual int stop () { return 0; } {
return 0;
}
virtual int stop ()
{
return 0;
}
PBD::EventLoop* event_loop () const; PBD::EventLoop* event_loop () const;
Glib::RefPtr<Glib::MainLoop> main_loop () const; Glib::RefPtr<Glib::MainLoop> main_loop () const;
@ -53,9 +60,7 @@ class SurfaceComponent
WebsocketsDispatcher& dispatcher () const; WebsocketsDispatcher& dispatcher () const;
protected: protected:
ArdourSurface::ArdourWebsockets& _surface; ArdourSurface::ArdourWebsockets& _surface;
}; };
#endif // surface_component_h #endif // surface_component_h

View file

@ -20,8 +20,8 @@
#include "ardour/plugin_insert.h" #include "ardour/plugin_insert.h"
#include "dispatcher.h"
#include "ardour_websockets.h" #include "ardour_websockets.h"
#include "dispatcher.h"
#include "state.h" #include "state.h"
using namespace ARDOUR; using namespace ARDOUR;
@ -35,8 +35,7 @@ WebsocketsDispatcher::_node_to_method = boost::assign::map_list_of
NODE_METHOD_PAIR (strip_pan) NODE_METHOD_PAIR (strip_pan)
NODE_METHOD_PAIR (strip_mute) NODE_METHOD_PAIR (strip_mute)
NODE_METHOD_PAIR (strip_plugin_enable) NODE_METHOD_PAIR (strip_plugin_enable)
NODE_METHOD_PAIR(strip_plugin_param_value) NODE_METHOD_PAIR (strip_plugin_param_value);
;
void void
WebsocketsDispatcher::dispatch (Client client, const NodeStateMessage& msg) WebsocketsDispatcher::dispatch (Client client, const NodeStateMessage& msg)

View file

@ -21,23 +21,21 @@
#include <boost/unordered_map.hpp> #include <boost/unordered_map.hpp>
#include "component.h"
#include "client.h" #include "client.h"
#include "component.h"
#include "message.h" #include "message.h"
class WebsocketsDispatcher : public SurfaceComponent class WebsocketsDispatcher : public SurfaceComponent
{ {
public: public:
WebsocketsDispatcher (ArdourSurface::ArdourWebsockets& surface)
WebsocketsDispatcher (ArdourSurface::ArdourWebsockets& surface) : SurfaceComponent (surface) {}; : SurfaceComponent (surface){};
virtual ~WebsocketsDispatcher (){}; virtual ~WebsocketsDispatcher (){};
void dispatch (Client, const NodeStateMessage&); void dispatch (Client, const NodeStateMessage&);
void update_all_nodes (Client); void update_all_nodes (Client);
private: private:
typedef void (WebsocketsDispatcher::*DispatcherMethod) (Client, const NodeStateMessage&); typedef void (WebsocketsDispatcher::*DispatcherMethod) (Client, const NodeStateMessage&);
typedef boost::unordered_map<std::string, DispatcherMethod> NodeMethodMap; typedef boost::unordered_map<std::string, DispatcherMethod> NodeMethodMap;
@ -55,7 +53,6 @@ class WebsocketsDispatcher : public SurfaceComponent
void update (Client, std::string, uint32_t, uint32_t, TypedValue); void update (Client, std::string, uint32_t, uint32_t, TypedValue);
void update (Client, std::string, uint32_t, uint32_t, uint32_t, TypedValue); void update (Client, std::string, uint32_t, uint32_t, uint32_t, TypedValue);
void update (Client, std::string, const AddressVector&, const ValueVector&); void update (Client, std::string, const AddressVector&, const ValueVector&);
}; };
#endif // websockets_dispatcher_h #endif // websockets_dispatcher_h

View file

@ -16,46 +16,51 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "ardour/meter.h"
#include "ardour/plugin_insert.h"
#include "ardour/session.h" #include "ardour/session.h"
#include "ardour/tempo.h" #include "ardour/tempo.h"
#include "ardour/plugin_insert.h"
#include "ardour/meter.h"
#include "feedback.h" #include "feedback.h"
#include "strips.h"
#include "globals.h" #include "globals.h"
#include "state.h"
#include "server.h" #include "server.h"
#include "state.h"
#include "strips.h"
using namespace ARDOUR; using namespace ARDOUR;
struct TempoObserver { struct TempoObserver {
void operator() (ArdourFeedback* p) { void operator() (ArdourFeedback* p)
{
p->update_all (Node::tempo, p->globals ().tempo ()); p->update_all (Node::tempo, p->globals ().tempo ());
} }
}; };
struct StripGainObserver { struct StripGainObserver {
void operator() (ArdourFeedback* p, uint32_t strip_n) { void operator() (ArdourFeedback* p, uint32_t strip_n)
{
// fires multiple times (4x as of ardour 6.0) // fires multiple times (4x as of ardour 6.0)
p->update_all (Node::strip_gain, strip_n, p->strips ().strip_gain (strip_n)); p->update_all (Node::strip_gain, strip_n, p->strips ().strip_gain (strip_n));
} }
}; };
struct StripPanObserver { struct StripPanObserver {
void operator() (ArdourFeedback* p, uint32_t strip_n) { void operator() (ArdourFeedback* p, uint32_t strip_n)
{
p->update_all (Node::strip_pan, strip_n, p->strips ().strip_pan (strip_n)); p->update_all (Node::strip_pan, strip_n, p->strips ().strip_pan (strip_n));
} }
}; };
struct StripMuteObserver { struct StripMuteObserver {
void operator() (ArdourFeedback* p, uint32_t strip_n) { void operator() (ArdourFeedback* p, uint32_t strip_n)
{
p->update_all (Node::strip_mute, strip_n, p->strips ().strip_mute (strip_n)); p->update_all (Node::strip_mute, strip_n, p->strips ().strip_mute (strip_n));
} }
}; };
struct PluginBypassObserver { struct PluginBypassObserver {
void operator() (ArdourFeedback* p, uint32_t strip_n, uint32_t plugin_n) { void operator() (ArdourFeedback* p, uint32_t strip_n, uint32_t plugin_n)
{
p->update_all (Node::strip_plugin_enable, strip_n, plugin_n, p->update_all (Node::strip_plugin_enable, strip_n, plugin_n,
p->strips ().strip_plugin_enabled (strip_n, plugin_n)); p->strips ().strip_plugin_enabled (strip_n, plugin_n));
} }
@ -63,7 +68,8 @@ struct PluginBypassObserver {
struct PluginParamValueObserver { struct PluginParamValueObserver {
void operator() (ArdourFeedback* p, uint32_t strip_n, uint32_t plugin_n, void operator() (ArdourFeedback* p, uint32_t strip_n, uint32_t plugin_n,
uint32_t param_n, boost::shared_ptr<AutomationControl> control) { uint32_t param_n, boost::shared_ptr<AutomationControl> control)
{
p->update_all (Node::strip_plugin_param_value, strip_n, plugin_n, param_n, p->update_all (Node::strip_plugin_param_value, strip_n, plugin_n, param_n,
ArdourStrips::plugin_param_value (control)); ArdourStrips::plugin_param_value (control));
} }
@ -215,6 +221,7 @@ ArdourFeedback::observe_strip_plugin_param_values (uint32_t strip_n,
control->Changed.connect (_signal_connections, MISSING_INVALIDATOR, control->Changed.connect (_signal_connections, MISSING_INVALIDATOR,
boost::bind<void> (PluginParamValueObserver (), this, strip_n, plugin_n, param_n, boost::bind<void> (PluginParamValueObserver (), this, strip_n, plugin_n, param_n,
control), event_loop ()); control),
event_loop ());
} }
} }

View file

@ -19,8 +19,8 @@
#ifndef ardour_feedback_h #ifndef ardour_feedback_h
#define ardour_feedback_h #define ardour_feedback_h
#include <glibmm/main.h>
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <glibmm/main.h>
#include "component.h" #include "component.h"
#include "typed_value.h" #include "typed_value.h"
@ -28,8 +28,8 @@
class ArdourFeedback : public SurfaceComponent class ArdourFeedback : public SurfaceComponent
{ {
public: public:
ArdourFeedback (ArdourSurface::ArdourWebsockets& surface)
ArdourFeedback (ArdourSurface::ArdourWebsockets& surface) : SurfaceComponent (surface) {}; : SurfaceComponent (surface){};
virtual ~ArdourFeedback (){}; virtual ~ArdourFeedback (){};
int start (); int start ();
@ -41,7 +41,6 @@ class ArdourFeedback : public SurfaceComponent
void update_all (std::string, uint32_t, uint32_t, uint32_t, TypedValue) const; void update_all (std::string, uint32_t, uint32_t, uint32_t, TypedValue) const;
private: private:
Glib::Threads::Mutex _client_state_lock; Glib::Threads::Mutex _client_state_lock;
PBD::ScopedConnectionList _signal_connections; PBD::ScopedConnectionList _signal_connections;
sigc::connection _periodic_connection; sigc::connection _periodic_connection;
@ -53,7 +52,6 @@ class ArdourFeedback : public SurfaceComponent
void observe_strip_plugins (uint32_t, boost::shared_ptr<ARDOUR::Stripable>); void observe_strip_plugins (uint32_t, boost::shared_ptr<ARDOUR::Stripable>);
void observe_strip_plugin_param_values (uint32_t, uint32_t, void observe_strip_plugin_param_values (uint32_t, uint32_t,
boost::shared_ptr<ARDOUR::PluginInsert>); boost::shared_ptr<ARDOUR::PluginInsert>);
}; };
#endif // ardour_feedback_h #endif // ardour_feedback_h

View file

@ -24,13 +24,12 @@
class ArdourGlobals : public SurfaceComponent class ArdourGlobals : public SurfaceComponent
{ {
public: public:
ArdourGlobals (ArdourSurface::ArdourWebsockets& surface)
ArdourGlobals (ArdourSurface::ArdourWebsockets& surface) : SurfaceComponent (surface) {}; : SurfaceComponent (surface){};
virtual ~ArdourGlobals (){}; virtual ~ArdourGlobals (){};
double tempo () const; double tempo () const;
void set_tempo (double); void set_tempo (double);
}; };
#endif // ardour_globals_h #endif // ardour_globals_h

View file

@ -68,6 +68,8 @@ static ControlProtocolDescriptor ardour_websockets_descriptor = {
/*request_buffer_factory */ ardour_websockets_request_buffer_factory /*request_buffer_factory */ ardour_websockets_request_buffer_factory
}; };
extern "C" ARDOURSURFACE_API ControlProtocolDescriptor* protocol_descriptor () { extern "C" ARDOURSURFACE_API ControlProtocolDescriptor*
protocol_descriptor ()
{
return &ardour_websockets_descriptor; return &ardour_websockets_descriptor;
} }

View file

@ -20,10 +20,10 @@
#include <iostream> #include <iostream>
#endif #endif
#include <sstream>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
#include <sstream>
#include "message.h" #include "message.h"
@ -65,7 +65,6 @@ NodeStateMessage::NodeStateMessage (void *buf, size_t len)
pt::ptree val = root.get_child ("val", pt::ptree ()); pt::ptree val = root.get_child ("val", pt::ptree ());
for (pt::ptree::iterator it = val.begin (); it != val.end (); ++it) { for (pt::ptree::iterator it = val.begin (); it != val.end (); ++it) {
std::string val = it->second.data (); std::string val = it->second.data ();
try { try {

View file

@ -24,22 +24,28 @@
class NodeStateMessage class NodeStateMessage
{ {
public: public:
NodeStateMessage (const NodeState& state); NodeStateMessage (const NodeState& state);
NodeStateMessage (void*, size_t); NodeStateMessage (void*, size_t);
size_t serialize (void*, size_t) const; size_t serialize (void*, size_t) const;
bool is_valid () const { return _valid; } bool is_valid () const
bool is_write () const { return _write; } {
const NodeState& state () const { return _state; } return _valid;
}
bool is_write () const
{
return _write;
}
const NodeState& state () const
{
return _state;
}
private: private:
bool _valid; bool _valid;
bool _write; bool _write;
NodeState _state; NodeState _state;
}; };
#endif // websockets_message_h #endif // websockets_message_h

View file

@ -20,8 +20,8 @@
#include <iostream> #include <iostream>
#endif #endif
#include "server.h"
#include "dispatcher.h" #include "dispatcher.h"
#include "server.h"
/* backport from libwebsockets 3.0, /* backport from libwebsockets 3.0,
* allow to compile on GNU/Linux with libwebsockets 2.x * allow to compile on GNU/Linux with libwebsockets 2.x
@ -44,7 +44,7 @@ WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface)
: SurfaceComponent (surface) : SurfaceComponent (surface)
, _lws_context (0) , _lws_context (0)
{ {
// keep references to all config for libwebsockets 2 /* keep references to all config for libwebsockets 2 */
lws_protocols proto; lws_protocols proto;
memset (&proto, 0, sizeof (lws_protocols)); memset (&proto, 0, sizeof (lws_protocols));
proto.name = "lws-ardour"; proto.name = "lws-ardour";
@ -77,17 +77,19 @@ WebsocketsServer::start ()
return -1; return -1;
} }
// add_poll_fd() should have been called once during lws_create_context() /* add_poll_fd() should have been called once during lws_create_context()
// if _fd_ctx is empty then LWS_CALLBACK_ADD_POLL_FD was not called * if _fd_ctx is empty then LWS_CALLBACK_ADD_POLL_FD was not called
// this means libwesockets was not compiled with LWS_WITH_EXTERNAL_POLL * this means libwesockets was not compiled with LWS_WITH_EXTERNAL_POLL
// - macos homebrew libwebsockets: disabled (3.2.2 as of Feb 2020) * - macos homebrew libwebsockets: disabled (3.2.2 as of Feb 2020)
// - linux ubuntu libwebsockets-dev: enabled (2.0.3 as of Feb 2020) but * - linux ubuntu libwebsockets-dev: enabled (2.0.3 as of Feb 2020) but
// #if defined(LWS_WITH_EXTERNAL_POLL) check is not reliable -- constant * #if defined(LWS_WITH_EXTERNAL_POLL) check is not reliable -- constant
// missing from /usr/include/lws_config.h * missing from /usr/include/lws_config.h
*/
if (_fd_ctx.empty ()) { if (_fd_ctx.empty ()) {
PBD::error << "ArdourWebsockets: check your libwebsockets was compiled" PBD::error << "ArdourWebsockets: check your libwebsockets was compiled"
" with LWS_WITH_EXTERNAL_POLL enabled" << endmsg; " with LWS_WITH_EXTERNAL_POLL enabled"
<< endmsg;
return -1; return -1;
} }
@ -124,7 +126,7 @@ WebsocketsServer::update_client (Client wsi, const NodeState& state, bool force)
} }
if (force || !it->second.has_state (state)) { if (force || !it->second.has_state (state)) {
// write to client only if state was updated /* write to client only if state was updated */
it->second.update_state (state); it->second.update_state (state);
it->second.output_buf ().push_back (NodeStateMessage (state)); it->second.output_buf ().push_back (NodeStateMessage (state));
lws_callback_on_writable (wsi); lws_callback_on_writable (wsi);
@ -142,7 +144,7 @@ WebsocketsServer::update_all_clients (const NodeState& state, bool force)
void void
WebsocketsServer::add_poll_fd (struct lws_pollargs* pa) WebsocketsServer::add_poll_fd (struct lws_pollargs* pa)
{ {
// fd can be SOCKET or int depending platform /* fd can be SOCKET or int depending platform */
lws_sockfd_type fd = pa->fd; lws_sockfd_type fd = pa->fd;
#ifdef PLATFORM_WINDOWS #ifdef PLATFORM_WINDOWS
@ -179,13 +181,14 @@ WebsocketsServer::mod_poll_fd (struct lws_pollargs *pa)
it->second.lws_pfd.events = pa->events; it->second.lws_pfd.events = pa->events;
if (pa->events & LWS_POLLOUT) { if (pa->events & LWS_POLLOUT) {
// libwebsockets wants to write but cannot find a way to update /* libwebsockets wants to write but cannot find a way to update
// an existing glib::iosource event flags using glibmm, * an existing glib::iosource event flags using glibmm,
// create another iosource and set to IO_OUT, it will be destroyed * create another iosource and set to IO_OUT, it will be destroyed
// after clearing POLLOUT (see 'else' body below) * after clearing POLLOUT (see 'else' body below)
*/
if (it->second.wg_iosrc) { if (it->second.wg_iosrc) {
// already polling for write /* already polling for write */
return; return;
} }
@ -251,7 +254,7 @@ WebsocketsServer::recv_client (Client wsi, void *buf, size_t len)
return; return;
} }
// avoid echo /* avoid echo */
it->second.update_state (msg.state ()); it->second.update_state (msg.state ());
dispatcher ().dispatch (wsi, msg); dispatcher ().dispatch (wsi, msg);
@ -270,7 +273,7 @@ WebsocketsServer::write_client (Client wsi)
return; return;
} }
// one lws_write() call per LWS_CALLBACK_SERVER_WRITEABLE callback /* one lws_write() call per LWS_CALLBACK_SERVER_WRITEABLE callback */
NodeStateMessage msg = pending.front (); NodeStateMessage msg = pending.front ();
pending.pop_front (); pending.pop_front ();
@ -295,7 +298,7 @@ WebsocketsServer::write_client (Client wsi)
bool bool
WebsocketsServer::io_handler (Glib::IOCondition ioc, lws_sockfd_type fd) WebsocketsServer::io_handler (Glib::IOCondition ioc, lws_sockfd_type fd)
{ {
// IO_IN=1, IO_PRI=2, IO_ERR=8, IO_HUP=16 /* IO_IN=1, IO_PRI=2, IO_ERR=8, IO_HUP=16 */
//printf ("io_handler ioc = %d\n", ioc); //printf ("io_handler ioc = %d\n", ioc);
LwsPollFdGlibSourceMap::iterator it = _fd_ctx.find (fd); LwsPollFdGlibSourceMap::iterator it = _fd_ctx.find (fd);

View file

@ -19,9 +19,9 @@
#ifndef websockets_server_h #ifndef websockets_server_h
#define websockets_server_h #define websockets_server_h
#include <boost/unordered_map.hpp>
#include <glibmm.h> #include <glibmm.h>
#include <libwebsockets.h> #include <libwebsockets.h>
#include <boost/unordered_map.hpp>
#if LWS_LIBRARY_VERSION_MAJOR < 3 #if LWS_LIBRARY_VERSION_MAJOR < 3
// <libwebsockets.h> includes <uv.h> which in turn includes // <libwebsockets.h> includes <uv.h> which in turn includes
@ -34,10 +34,10 @@
// version 3 in order to keep things simpler for the end user // version 3 in order to keep things simpler for the end user
#endif #endif
#include "component.h"
#include "client.h" #include "client.h"
#include "state.h" #include "component.h"
#include "message.h" #include "message.h"
#include "state.h"
#define WEBSOCKET_LISTEN_PORT 9000 #define WEBSOCKET_LISTEN_PORT 9000
@ -51,7 +51,6 @@ struct LwsPollFdGlibSource {
class WebsocketsServer : public SurfaceComponent class WebsocketsServer : public SurfaceComponent
{ {
public: public:
WebsocketsServer (ArdourSurface::ArdourWebsockets&); WebsocketsServer (ArdourSurface::ArdourWebsockets&);
virtual ~WebsocketsServer (){}; virtual ~WebsocketsServer (){};
@ -62,7 +61,6 @@ class WebsocketsServer : public SurfaceComponent
void update_all_clients (const NodeState&, bool); void update_all_clients (const NodeState&, bool);
private: private:
struct lws_protocols _lws_proto[2]; struct lws_protocols _lws_proto[2];
struct lws_context_creation_info _lws_info; struct lws_context_creation_info _lws_info;
struct lws_context* _lws_context; struct lws_context* _lws_context;
@ -90,7 +88,6 @@ class WebsocketsServer : public SurfaceComponent
int ioc_to_events (Glib::IOCondition); int ioc_to_events (Glib::IOCondition);
static int lws_callback (struct lws*, enum lws_callback_reasons, void*, void*, size_t); static int lws_callback (struct lws*, enum lws_callback_reasons, void*, void*, size_t);
}; };
#endif // websockets_server_h #endif // websockets_server_h

View file

@ -16,20 +16,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <sstream>
#include <boost/unordered_set.hpp> #include <boost/unordered_set.hpp>
#include <sstream>
#include "state.h" #include "state.h"
NodeState::NodeState () {} NodeState::NodeState () {}
NodeState::NodeState (std::string node) NodeState::NodeState (std::string node)
: _node (node) { } : _node (node)
{
}
NodeState::NodeState (std::string node, AddressVector addr, ValueVector val) NodeState::NodeState (std::string node, AddressVector addr, ValueVector val)
: _node (node) : _node (node)
, _addr (addr) , _addr (addr)
, _val (val) { } , _val (val)
{
}
std::string std::string
NodeState::debug_str () const NodeState::debug_str () const
@ -38,7 +42,8 @@ NodeState::debug_str () const
s << "node = " << _node; s << "node = " << _node;
if (!_addr.empty ()) { if (!_addr.empty ()) {
s << std::endl << " addr = "; s << std::endl
<< " addr = ";
for (AddressVector::const_iterator it = _addr.begin (); it != _addr.end (); ++it) { for (AddressVector::const_iterator it = _addr.begin (); it != _addr.end (); ++it) {
s << *it << ";"; s << *it << ";";
@ -46,7 +51,8 @@ NodeState::debug_str () const
} }
for (ValueVector::const_iterator it = _val.begin (); it != _val.end (); ++it) { for (ValueVector::const_iterator it = _val.begin (); it != _val.end (); ++it) {
s << std::endl << " val " << it->debug_str (); s << std::endl
<< " val " << it->debug_str ();
} }
return s.str (); return s.str ();
@ -107,7 +113,8 @@ NodeState::operator== (const NodeState& other) const
return node_addr_hash () == other.node_addr_hash (); return node_addr_hash () == other.node_addr_hash ();
} }
std::size_t hash_value (const NodeState &state) std::size_t
hash_value (const NodeState& state)
{ {
return state.node_addr_hash (); return state.node_addr_hash ();
} }

View file

@ -19,17 +19,18 @@
#ifndef node_state_h #ifndef node_state_h
#define node_state_h #define node_state_h
#include <stdint.h>
#include <climits> #include <climits>
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
#include <stdint.h>
#include <vector> #include <vector>
#include "typed_value.h" #include "typed_value.h"
#define ADDR_NONE UINT_MAX #define ADDR_NONE UINT_MAX
namespace Node { namespace Node
{
const std::string tempo = "tempo"; const std::string tempo = "tempo";
const std::string strip_desc = "strip_desc"; const std::string strip_desc = "strip_desc";
const std::string strip_meter = "strip_meter"; const std::string strip_meter = "strip_meter";
@ -40,22 +41,24 @@ namespace Node {
const std::string strip_plugin_enable = "strip_plugin_enable"; const std::string strip_plugin_enable = "strip_plugin_enable";
const std::string strip_plugin_param_desc = "strip_plugin_param_desc"; const std::string strip_plugin_param_desc = "strip_plugin_param_desc";
const std::string strip_plugin_param_value = "strip_plugin_param_value"; const std::string strip_plugin_param_value = "strip_plugin_param_value";
} } // namespace Node
typedef std::vector<uint32_t> AddressVector; typedef std::vector<uint32_t> AddressVector;
typedef std::vector<TypedValue> ValueVector; typedef std::vector<TypedValue> ValueVector;
class NodeState { class NodeState
{
public: public:
NodeState (); NodeState ();
NodeState (std::string); NodeState (std::string);
NodeState (std::string, AddressVector, ValueVector = ValueVector ()); NodeState (std::string, AddressVector, ValueVector = ValueVector ());
std::string debug_str () const; std::string debug_str () const;
std::string node () const { return _node; } std::string node () const
{
return _node;
}
int n_addr () const; int n_addr () const;
uint32_t nth_addr (int) const; uint32_t nth_addr (int) const;
@ -70,13 +73,12 @@ class NodeState {
bool operator== (const NodeState& other) const; bool operator== (const NodeState& other) const;
private: private:
std::string _node; std::string _node;
AddressVector _addr; AddressVector _addr;
ValueVector _val; ValueVector _val;
}; };
std::size_t hash_value (const NodeState&); std::size_t
hash_value (const NodeState&);
#endif // node_state_h #endif // node_state_h

View file

@ -16,9 +16,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include "ardour/session.h"
#include "ardour/plugin_insert.h"
#include "ardour/dB.h" #include "ardour/dB.h"
#include "ardour/plugin_insert.h"
#include "ardour/session.h"
#include "pbd/controllable.h" #include "pbd/controllable.h"
#include "strips.h" #include "strips.h"
@ -28,7 +28,7 @@ using namespace ARDOUR;
int int
ArdourStrips::start () ArdourStrips::start ()
{ {
// take an indexed snapshot of current strips /* take an indexed snapshot of current strips */
StripableList strips; StripableList strips;
session ().get_stripables (strips, PresentationInfo::AllStripables); session ().get_stripables (strips, PresentationInfo::AllStripables);
@ -85,7 +85,7 @@ ArdourStrips::set_strip_gain (uint32_t strip_n, double db)
double double
ArdourStrips::strip_pan (uint32_t strip_n) const ArdourStrips::strip_pan (uint32_t strip_n) const
{ {
// scale from [0.0 ; 1.0] to [-1.0 ; 1.0] /* scale from [0.0 ; 1.0] to [-1.0 ; 1.0] */
return 2.0 * nth_strip (strip_n)->pan_azimuth_control ()->get_value () - 1.0; return 2.0 * nth_strip (strip_n)->pan_azimuth_control ()->get_value () - 1.0;
} }

View file

@ -25,8 +25,8 @@
class ArdourStrips : public SurfaceComponent class ArdourStrips : public SurfaceComponent
{ {
public: public:
ArdourStrips (ArdourSurface::ArdourWebsockets& surface)
ArdourStrips (ArdourSurface::ArdourWebsockets& surface) : SurfaceComponent (surface) {}; : SurfaceComponent (surface){};
virtual ~ArdourStrips (){}; virtual ~ArdourStrips (){};
int start (); int start ();
@ -61,10 +61,8 @@ class ArdourStrips : public SurfaceComponent
static TypedValue plugin_param_value (boost::shared_ptr<ARDOUR::AutomationControl>); static TypedValue plugin_param_value (boost::shared_ptr<ARDOUR::AutomationControl>);
private: private:
typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > StripableVector; typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > StripableVector;
StripableVector _strips; StripableVector _strips;
}; };
#endif // ardour_strips_h #endif // ardour_strips_h

View file

@ -16,10 +16,10 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/ */
#include <boost/lexical_cast.hpp>
#include <cmath> #include <cmath>
#include <limits> #include <limits>
#include <string> #include <string>
#include <boost/lexical_cast.hpp>
#include "typed_value.h" #include "typed_value.h"
@ -29,35 +29,44 @@ TypedValue::TypedValue ()
: _type (Empty) : _type (Empty)
, _b (false) , _b (false)
, _i (0) , _i (0)
, _d (0) { } , _d (0)
{
}
TypedValue::TypedValue (bool value) TypedValue::TypedValue (bool value)
: _type (Bool) : _type (Bool)
, _b (value) , _b (value)
, _i (0) , _i (0)
, _d (0) { } , _d (0)
{
}
TypedValue::TypedValue (int value) TypedValue::TypedValue (int value)
: _type (Int) : _type (Int)
, _b (false) , _b (false)
, _i (value) , _i (value)
, _d (0) { } , _d (0)
{
}
TypedValue::TypedValue (double value) TypedValue::TypedValue (double value)
: _type (Double) : _type (Double)
, _b (false) , _b (false)
, _i (0) , _i (0)
, _d (value) { } , _d (value)
{
}
TypedValue::TypedValue (std::string value) TypedValue::TypedValue (std::string value)
: _type (String) : _type (String)
, _b (false) , _b (false)
, _i (0) , _i (0)
, _d (0) , _d (0)
, _s (value) { } , _s (value)
{
}
TypedValue::operator TypedValue::operator bool () const
bool () const
{ {
switch (_type) { switch (_type) {
case Bool: case Bool:
@ -73,8 +82,7 @@ bool () const
} }
} }
TypedValue::operator TypedValue::operator int () const
int () const
{ {
switch (_type) { switch (_type) {
case Int: case Int:
@ -94,8 +102,7 @@ int () const
} }
} }
TypedValue::operator TypedValue::operator double () const
double () const
{ {
switch (_type) { switch (_type) {
case Double: case Double:
@ -115,8 +122,7 @@ double () const
} }
} }
TypedValue::operator TypedValue::operator std::string () const
std::string () const
{ {
switch (_type) { switch (_type) {
case String: case String:
@ -136,9 +142,10 @@ bool
TypedValue::operator== (const TypedValue& other) const TypedValue::operator== (const TypedValue& other) const
{ {
if (_type != other._type) { if (_type != other._type) {
// make an exception when comparing doubles and ints /* make an exception when comparing doubles and ints
// for example browser json implementations will send * for example browser json implementations will send
// 1 instead of 1.0 removing any type hint * 1 instead of 1.0 removing any type hint
*/
if ((_type == Int) && (other._type == Double)) { if ((_type == Int) && (other._type == Double)) {
return fabs (static_cast<double> (_i) - other._d) < DBL_TOLERANCE; return fabs (static_cast<double> (_i) - other._d) < DBL_TOLERANCE;
} else if ((_type == Double) && (other._type == Int)) { } else if ((_type == Double) && (other._type == Int)) {
@ -155,9 +162,7 @@ TypedValue::operator== (const TypedValue& other) const
return _i == other._i; return _i == other._i;
case Double: { case Double: {
double inf = std::numeric_limits<double>::infinity (); double inf = std::numeric_limits<double>::infinity ();
return ((_d == inf) && (other._d == inf)) return ((_d == inf) && (other._d == inf)) || ((_d == -inf) && (other._d == -inf)) || (fabs (_d - other._d) < DBL_TOLERANCE);
|| ((_d == -inf) && (other._d == -inf))
|| (fabs (_d - other._d) < DBL_TOLERANCE);
} }
case String: case String:
return _s == other._s; return _s == other._s;

View file

@ -24,7 +24,6 @@
class TypedValue class TypedValue
{ {
public: public:
enum Type { enum Type {
Empty, Empty,
Bool, Bool,
@ -39,8 +38,14 @@ class TypedValue
TypedValue (double); TypedValue (double);
TypedValue (std::string); TypedValue (std::string);
bool empty () const { return _type == Empty; }; bool empty () const
Type type () const { return _type; }; {
return _type == Empty;
};
Type type () const
{
return _type;
};
operator bool () const; operator bool () const;
operator int () const; operator int () const;
@ -53,13 +58,11 @@ class TypedValue
std::string debug_str () const; std::string debug_str () const;
private: private:
Type _type; Type _type;
bool _b; bool _b;
int _i; int _i;
double _d; double _d;
std::string _s; std::string _s;
}; };
#endif // typed_value_h #endif // typed_value_h