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

@ -35,7 +35,7 @@ using namespace ArdourSurface;
#include "pbd/abstract_ui.cc" // instantiate template
ArdourWebsockets::ArdourWebsockets (Session& s)
: ControlProtocol (s, X_(SURFACE_NAME))
: ControlProtocol (s, X_ (SURFACE_NAME))
, AbstractUI<ArdourWebsocketsUIRequest> (name ())
, _strips (*this)
, _globals (*this)
@ -52,7 +52,7 @@ ArdourWebsockets::ArdourWebsockets (Session& s)
ArdourWebsockets::~ArdourWebsockets ()
{
stop();
stop ();
}
void*
@ -105,10 +105,10 @@ ArdourWebsockets::do_request (ArdourWebsocketsUIRequest* req)
int
ArdourWebsockets::start ()
{
// startup the event loop thread
/* startup the event loop thread */
BaseUI::run ();
for (std::vector<SurfaceComponent *>::iterator it = _components.begin ();
for (std::vector<SurfaceComponent*>::iterator it = _components.begin ();
it != _components.end (); ++it) {
int rc = (*it)->start ();
if (rc != 0) {
@ -122,8 +122,9 @@ ArdourWebsockets::start ()
}
int
ArdourWebsockets::stop () {
for (std::vector<SurfaceComponent *>::iterator it = _components.begin ();
ArdourWebsockets::stop ()
{
for (std::vector<SurfaceComponent*>::iterator it = _components.begin ();
it != _components.end (); ++it) {
(*it)->stop ();
}

View file

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

View file

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

View file

@ -22,7 +22,7 @@
PBD::EventLoop*
SurfaceComponent::event_loop () const
{
return static_cast<PBD::EventLoop*>(&_surface);
return static_cast<PBD::EventLoop*> (&_surface);
}
Glib::RefPtr<Glib::MainLoop>

View file

@ -24,8 +24,9 @@
#include "ardour/session.h"
#include "pbd/event_loop.h"
namespace ArdourSurface {
class ArdourWebsockets;
namespace ArdourSurface
{
class ArdourWebsockets;
}
class ArdourStrips;
@ -35,27 +36,31 @@ class WebsocketsDispatcher;
class SurfaceComponent
{
public:
public:
SurfaceComponent (ArdourSurface::ArdourWebsockets& surface)
: _surface (surface){};
SurfaceComponent (ArdourSurface::ArdourWebsockets& surface) : _surface (surface) {};
virtual ~SurfaceComponent (){};
virtual ~SurfaceComponent () {};
virtual int start () { return 0; }
virtual int stop () { return 0; }
virtual int start ()
{
return 0;
}
virtual int stop ()
{
return 0;
}
PBD::EventLoop* event_loop () const;
Glib::RefPtr<Glib::MainLoop> main_loop() const;
Glib::RefPtr<Glib::MainLoop> main_loop () const;
ARDOUR::Session& session () const;
ArdourStrips& strips () const;
ArdourGlobals& globals () const;
WebsocketsServer& server () const;
WebsocketsDispatcher& dispatcher () const;
protected:
protected:
ArdourSurface::ArdourWebsockets& _surface;
};
#endif // surface_component_h

View file

@ -20,23 +20,22 @@
#include "ardour/plugin_insert.h"
#include "dispatcher.h"
#include "ardour_websockets.h"
#include "dispatcher.h"
#include "state.h"
using namespace ARDOUR;
#define NODE_METHOD_PAIR(x) (Node::x, &WebsocketsDispatcher::x ## _handler)
#define NODE_METHOD_PAIR(x) (Node::x, &WebsocketsDispatcher::x##_handler)
WebsocketsDispatcher::NodeMethodMap
WebsocketsDispatcher::_node_to_method = boost::assign::map_list_of
NODE_METHOD_PAIR(tempo)
NODE_METHOD_PAIR(strip_gain)
NODE_METHOD_PAIR(strip_pan)
NODE_METHOD_PAIR(strip_mute)
NODE_METHOD_PAIR(strip_plugin_enable)
NODE_METHOD_PAIR(strip_plugin_param_value)
;
WebsocketsDispatcher::_node_to_method = boost::assign::map_list_of
NODE_METHOD_PAIR (tempo)
NODE_METHOD_PAIR (strip_gain)
NODE_METHOD_PAIR (strip_pan)
NODE_METHOD_PAIR (strip_mute)
NODE_METHOD_PAIR (strip_plugin_enable)
NODE_METHOD_PAIR (strip_plugin_param_value);
void
WebsocketsDispatcher::dispatch (Client client, const NodeStateMessage& msg)
@ -46,7 +45,7 @@ WebsocketsDispatcher::dispatch (Client client, const NodeStateMessage& msg)
try {
(this->*it->second) (client, msg);
} catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
std::cerr << e.what () << std::endl;
}
}
}
@ -68,7 +67,7 @@ WebsocketsDispatcher::update_all_nodes (Client client)
update (client, Node::strip_pan, strip_n, strips ().strip_pan (strip_n));
update (client, Node::strip_mute, strip_n, strips ().strip_mute (strip_n));
for (uint32_t plugin_n = 0 ; ; ++plugin_n) {
for (uint32_t plugin_n = 0;; ++plugin_n) {
boost::shared_ptr<PluginInsert> insert = strips ()
.strip_plugin_insert (strip_n, plugin_n);
if (!insert) {
@ -77,7 +76,7 @@ WebsocketsDispatcher::update_all_nodes (Client client)
boost::shared_ptr<Plugin> plugin = insert->plugin ();
update (client, Node::strip_plugin_desc, strip_n, plugin_n,
static_cast<std::string>(plugin->name ()));
static_cast<std::string> (plugin->name ()));
update (client, Node::strip_plugin_enable, strip_n, plugin_n,
strips ().strip_plugin_enabled (strip_n, plugin_n));
@ -101,14 +100,14 @@ WebsocketsDispatcher::update_all_nodes (Client client)
ParameterDescriptor pd = a_ctrl->desc ();
if (pd.toggled) {
val.push_back (std::string("b"));
val.push_back (std::string ("b"));
} else if (pd.enumeration || pd.integer_step) {
val.push_back (std::string("i"));
val.push_back (std::string ("i"));
val.push_back (pd.lower);
val.push_back (pd.upper);
val.push_back (pd.integer_step);
} else {
val.push_back (std::string("d"));
val.push_back (std::string ("d"));
val.push_back (pd.lower);
val.push_back (pd.upper);
val.push_back (pd.logarithmic);
@ -153,7 +152,7 @@ WebsocketsDispatcher::strip_pan_handler (Client client, const NodeStateMessage&
if (msg.is_write ()) {
strips ().set_strip_pan (strip_id, msg.state ().nth_val (0));
} else {
update (client, Node::strip_pan, strip_id, strips ().strip_pan(strip_id));
update (client, Node::strip_pan, strip_id, strips ().strip_pan (strip_id));
}
}

View file

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

View file

@ -16,46 +16,51 @@
* 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/tempo.h"
#include "ardour/plugin_insert.h"
#include "ardour/meter.h"
#include "feedback.h"
#include "strips.h"
#include "globals.h"
#include "state.h"
#include "server.h"
#include "state.h"
#include "strips.h"
using namespace ARDOUR;
struct TempoObserver {
void operator() (ArdourFeedback* p) {
void operator() (ArdourFeedback* p)
{
p->update_all (Node::tempo, p->globals ().tempo ());
}
};
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)
p->update_all (Node::strip_gain, strip_n, p->strips ().strip_gain (strip_n));
}
};
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));
}
};
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));
}
};
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->strips ().strip_plugin_enabled (strip_n, plugin_n));
}
@ -63,7 +68,8 @@ struct PluginBypassObserver {
struct PluginParamValueObserver {
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,
ArdourStrips::plugin_param_value (control));
}
@ -143,7 +149,7 @@ ArdourFeedback::poll () const
boost::shared_ptr<Stripable> strip = strips ().nth_strip (strip_n);
boost::shared_ptr<PeakMeter> meter = strip->peak_meter ();
float db = meter ? meter->meter_level (0, MeterMCP) : -193;
update_all (Node::strip_meter, strip_n, static_cast<double>(db));
update_all (Node::strip_meter, strip_n, static_cast<double> (db));
}
return true;
@ -180,7 +186,7 @@ ArdourFeedback::observe_strips ()
void
ArdourFeedback::observe_strip_plugins (uint32_t strip_n, boost::shared_ptr<ARDOUR::Stripable> strip)
{
for (uint32_t plugin_n = 0 ; ; ++plugin_n) {
for (uint32_t plugin_n = 0;; ++plugin_n) {
boost::shared_ptr<PluginInsert> insert = strips ().strip_plugin_insert (strip_n, plugin_n);
if (!insert) {
break;
@ -215,6 +221,7 @@ ArdourFeedback::observe_strip_plugin_param_values (uint32_t strip_n,
control->Changed.connect (_signal_connections, MISSING_INVALIDATOR,
boost::bind<void> (PluginParamValueObserver (), this, strip_n, plugin_n, param_n,
control), event_loop ());
control),
event_loop ());
}
}

View file

@ -19,18 +19,18 @@
#ifndef ardour_feedback_h
#define ardour_feedback_h
#include <glibmm/main.h>
#include <boost/shared_ptr.hpp>
#include <glibmm/main.h>
#include "component.h"
#include "typed_value.h"
class ArdourFeedback : public SurfaceComponent
{
public:
ArdourFeedback (ArdourSurface::ArdourWebsockets& surface) : SurfaceComponent (surface) {};
virtual ~ArdourFeedback () {};
public:
ArdourFeedback (ArdourSurface::ArdourWebsockets& surface)
: SurfaceComponent (surface){};
virtual ~ArdourFeedback (){};
int start ();
int stop ();
@ -40,8 +40,7 @@ class ArdourFeedback : public SurfaceComponent
void update_all (std::string, 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;
PBD::ScopedConnectionList _signal_connections;
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_plugin_param_values (uint32_t, uint32_t,
boost::shared_ptr<ARDOUR::PluginInsert>);
};
#endif // ardour_feedback_h

View file

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

View file

@ -68,6 +68,8 @@ static ControlProtocolDescriptor ardour_websockets_descriptor = {
/*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;
}

View file

@ -20,18 +20,18 @@
#include <iostream>
#endif
#include <sstream>
#include <boost/lexical_cast.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp>
#include <sstream>
#include "message.h"
// JSON does not support Infinity or NaN
#define XSTR(s) STR(s)
#define XSTR(s) STR (s)
#define STR(s) #s
#define JSON_INF 1.0e+128
#define JSON_INF_STR XSTR(JSON_INF)
#define JSON_INF_STR XSTR (JSON_INF)
namespace pt = boost::property_tree;
@ -42,12 +42,12 @@ NodeStateMessage::NodeStateMessage (const NodeState& state)
_write = state.n_val () > 0;
}
NodeStateMessage::NodeStateMessage (void *buf, size_t len)
NodeStateMessage::NodeStateMessage (void* buf, size_t len)
: _valid (false)
, _write (false)
{
try {
std::string s (static_cast<char *>(buf), len);
std::string s (static_cast<char*> (buf), len);
std::istringstream is (s);
pt::ptree root;
@ -59,20 +59,19 @@ NodeStateMessage::NodeStateMessage (void *buf, size_t len)
for (pt::ptree::iterator it = addr.begin (); it != addr.end (); ++it) {
// throws if datatype not uint32_t
_state.add_addr (boost::lexical_cast<uint32_t>(it->second.data ()));
_state.add_addr (boost::lexical_cast<uint32_t> (it->second.data ()));
}
pt::ptree val = root.get_child ("val", pt::ptree ());
for (pt::ptree::iterator it = val.begin (); it != val.end (); ++it) {
std::string val = it->second.data ();
try {
_state.add_val (boost::lexical_cast<int>(val));
_state.add_val (boost::lexical_cast<int> (val));
} catch (const boost::bad_lexical_cast&) {
try {
double d = boost::lexical_cast<double>(val);
double d = boost::lexical_cast<double> (val);
if (d >= JSON_INF) {
d = std::numeric_limits<double>::infinity ();
} else if (d <= -JSON_INF) {
@ -105,7 +104,7 @@ NodeStateMessage::NodeStateMessage (void *buf, size_t len)
}
size_t
NodeStateMessage::serialize (void *buf, size_t len) const
NodeStateMessage::serialize (void* buf, size_t len) const
{
// boost json writes all values as strings, we do not want that
@ -150,13 +149,13 @@ NodeStateMessage::serialize (void *buf, size_t len) const
ss << "null";
break;
case TypedValue::Bool:
ss << (static_cast<bool>(val) ? "true" : "false");
ss << (static_cast<bool> (val) ? "true" : "false");
break;
case TypedValue::Int:
ss << static_cast<int>(val);
ss << static_cast<int> (val);
break;
case TypedValue::Double: {
double d = static_cast<double>(val);
double d = static_cast<double> (val);
if (d == std::numeric_limits<double>::infinity ()) {
ss << JSON_INF_STR;
} else if (d == -std::numeric_limits<double>::infinity ()) {
@ -167,7 +166,7 @@ NodeStateMessage::serialize (void *buf, size_t len) const
break;
}
case TypedValue::String:
ss << '"' << static_cast<std::string>(val) << '"';
ss << '"' << static_cast<std::string> (val) << '"';
break;
default:
break;
@ -180,7 +179,7 @@ NodeStateMessage::serialize (void *buf, size_t len) const
ss << '}';
std::string s = ss.str ();
const char *cs = s.c_str ();
const char* cs = s.c_str ();
size_t cs_sz = strlen (cs);
if (len < cs_sz) {

View file

@ -23,23 +23,29 @@
class NodeStateMessage
{
public:
public:
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_write () const { return _write; }
const NodeState& state () const { return _state; }
private:
bool is_valid () const
{
return _valid;
}
bool is_write () const
{
return _write;
}
const NodeState& state () const
{
return _state;
}
private:
bool _valid;
bool _write;
NodeState _state;
};
#endif // websockets_message_h

View file

@ -20,22 +20,22 @@
#include <iostream>
#endif
#include "server.h"
#include "dispatcher.h"
#include "server.h"
/* backport from libwebsockets 3.0,
* allow to compile on GNU/Linux with libwebsockets 2.x
*/
#ifndef PLATFORM_WINDOWS
# ifndef LWS_POLLHUP
# define LWS_POLLHUP (POLLHUP|POLLERR)
# endif
# ifndef LWS_POLLIN
# define LWS_POLLIN (POLLIN)
# endif
# ifndef LWS_POLLOUT
# define LWS_POLLOUT (POLLOUT)
# endif
#ifndef LWS_POLLHUP
#define LWS_POLLHUP (POLLHUP | POLLERR)
#endif
#ifndef LWS_POLLIN
#define LWS_POLLIN (POLLIN)
#endif
#ifndef LWS_POLLOUT
#define LWS_POLLOUT (POLLOUT)
#endif
#endif
using namespace Glib;
@ -44,9 +44,9 @@ WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface)
: SurfaceComponent (surface)
, _lws_context (0)
{
// keep references to all config for libwebsockets 2
/* keep references to all config for libwebsockets 2 */
lws_protocols proto;
memset (&proto, 0, sizeof(lws_protocols));
memset (&proto, 0, sizeof (lws_protocols));
proto.name = "lws-ardour";
proto.callback = WebsocketsServer::lws_callback;
proto.per_session_data_size = 0;
@ -57,9 +57,9 @@ WebsocketsServer::WebsocketsServer (ArdourSurface::ArdourWebsockets& surface)
proto.tx_packet_size = 0;
#endif
_lws_proto[0] = proto;
memset (&_lws_proto[1], 0, sizeof(lws_protocols));
memset (&_lws_proto[1], 0, sizeof (lws_protocols));
memset (&_lws_info, 0, sizeof(lws_context_creation_info));
memset (&_lws_info, 0, sizeof (lws_context_creation_info));
_lws_info.port = WEBSOCKET_LISTEN_PORT;
_lws_info.protocols = _lws_proto;
_lws_info.uid = -1;
@ -77,17 +77,19 @@ WebsocketsServer::start ()
return -1;
}
// 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
// this means libwesockets was not compiled with LWS_WITH_EXTERNAL_POLL
// - macos homebrew libwebsockets: disabled (3.2.2 as of Feb 2020)
// - linux ubuntu libwebsockets-dev: enabled (2.0.3 as of Feb 2020) but
// #if defined(LWS_WITH_EXTERNAL_POLL) check is not reliable -- constant
// missing from /usr/include/lws_config.h
/* 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
* this means libwesockets was not compiled with LWS_WITH_EXTERNAL_POLL
* - macos homebrew libwebsockets: disabled (3.2.2 as of Feb 2020)
* - linux ubuntu libwebsockets-dev: enabled (2.0.3 as of Feb 2020) but
* #if defined(LWS_WITH_EXTERNAL_POLL) check is not reliable -- constant
* missing from /usr/include/lws_config.h
*/
if (_fd_ctx.empty ()) {
PBD::error << "ArdourWebsockets: check your libwebsockets was compiled"
" with LWS_WITH_EXTERNAL_POLL enabled" << endmsg;
" with LWS_WITH_EXTERNAL_POLL enabled"
<< endmsg;
return -1;
}
@ -124,7 +126,7 @@ WebsocketsServer::update_client (Client wsi, const NodeState& state, bool force)
}
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.output_buf ().push_back (NodeStateMessage (state));
lws_callback_on_writable (wsi);
@ -140,9 +142,9 @@ WebsocketsServer::update_all_clients (const NodeState& state, bool force)
}
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;
#ifdef PLATFORM_WINDOWS
@ -163,13 +165,13 @@ WebsocketsServer::add_poll_fd (struct lws_pollargs *pa)
ctx.lws_pfd = lws_pfd;
ctx.g_channel = g_channel;
ctx.rg_iosrc = rg_iosrc;
ctx.wg_iosrc = Glib::RefPtr<Glib::IOSource>(0);
ctx.wg_iosrc = Glib::RefPtr<Glib::IOSource> (0);
_fd_ctx[fd] = ctx;
}
void
WebsocketsServer::mod_poll_fd (struct lws_pollargs *pa)
WebsocketsServer::mod_poll_fd (struct lws_pollargs* pa)
{
LwsPollFdGlibSourceMap::iterator it = _fd_ctx.find (pa->fd);
if (it == _fd_ctx.end ()) {
@ -179,13 +181,14 @@ WebsocketsServer::mod_poll_fd (struct lws_pollargs *pa)
it->second.lws_pfd.events = pa->events;
if (pa->events & LWS_POLLOUT) {
// libwebsockets wants to write but cannot find a way to update
// an existing glib::iosource event flags using glibmm,
// create another iosource and set to IO_OUT, it will be destroyed
// after clearing POLLOUT (see 'else' body below)
/* libwebsockets wants to write but cannot find a way to update
* an existing glib::iosource event flags using glibmm,
* create another iosource and set to IO_OUT, it will be destroyed
* after clearing POLLOUT (see 'else' body below)
*/
if (it->second.wg_iosrc) {
// already polling for write
/* already polling for write */
return;
}
@ -196,13 +199,13 @@ WebsocketsServer::mod_poll_fd (struct lws_pollargs *pa)
} else {
if (it->second.wg_iosrc) {
it->second.wg_iosrc->destroy ();
it->second.wg_iosrc = Glib::RefPtr<Glib::IOSource>(0);
it->second.wg_iosrc = Glib::RefPtr<Glib::IOSource> (0);
}
}
}
void
WebsocketsServer::del_poll_fd (struct lws_pollargs *pa)
WebsocketsServer::del_poll_fd (struct lws_pollargs* pa)
{
LwsPollFdGlibSourceMap::iterator it = _fd_ctx.find (pa->fd);
if (it == _fd_ctx.end ()) {
@ -235,7 +238,7 @@ WebsocketsServer::del_client (Client wsi)
}
void
WebsocketsServer::recv_client (Client wsi, void *buf, size_t len)
WebsocketsServer::recv_client (Client wsi, void* buf, size_t len)
{
NodeStateMessage msg (buf, len);
if (!msg.is_valid ()) {
@ -251,7 +254,7 @@ WebsocketsServer::recv_client (Client wsi, void *buf, size_t len)
return;
}
// avoid echo
/* avoid echo */
it->second.update_state (msg.state ());
dispatcher ().dispatch (wsi, msg);
@ -270,7 +273,7 @@ WebsocketsServer::write_client (Client wsi)
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 ();
pending.pop_front ();
@ -295,7 +298,7 @@ WebsocketsServer::write_client (Client wsi)
bool
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);
LwsPollFdGlibSourceMap::iterator it = _fd_ctx.find (fd);
@ -303,7 +306,7 @@ WebsocketsServer::io_handler (Glib::IOCondition ioc, lws_sockfd_type fd)
return false;
}
struct lws_pollfd *lws_pfd = &it->second.lws_pfd;
struct lws_pollfd* lws_pfd = &it->second.lws_pfd;
lws_pfd->revents = ioc_to_events (ioc);
if (lws_service_fd (_lws_context, lws_pfd) < 0) {
@ -350,23 +353,23 @@ WebsocketsServer::ioc_to_events (IOCondition ioc)
}
int
WebsocketsServer::lws_callback(struct lws* wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len)
WebsocketsServer::lws_callback (struct lws* wsi, enum lws_callback_reasons reason,
void* user, void* in, size_t len)
{
void *ctx_userdata = lws_context_user (lws_get_context (wsi));
WebsocketsServer *server = static_cast<WebsocketsServer *>(ctx_userdata);
void* ctx_userdata = lws_context_user (lws_get_context (wsi));
WebsocketsServer* server = static_cast<WebsocketsServer*> (ctx_userdata);
switch (reason) {
case LWS_CALLBACK_ADD_POLL_FD:
server->add_poll_fd (static_cast<struct lws_pollargs *>(in));
server->add_poll_fd (static_cast<struct lws_pollargs*> (in));
break;
case LWS_CALLBACK_CHANGE_MODE_POLL_FD:
server->mod_poll_fd (static_cast<struct lws_pollargs *>(in));
server->mod_poll_fd (static_cast<struct lws_pollargs*> (in));
break;
case LWS_CALLBACK_DEL_POLL_FD:
server->del_poll_fd (static_cast<struct lws_pollargs *>(in));
server->del_poll_fd (static_cast<struct lws_pollargs*> (in));
break;
case LWS_CALLBACK_ESTABLISHED:

View file

@ -19,9 +19,9 @@
#ifndef websockets_server_h
#define websockets_server_h
#include <boost/unordered_map.hpp>
#include <glibmm.h>
#include <libwebsockets.h>
#include <boost/unordered_map.hpp>
#if LWS_LIBRARY_VERSION_MAJOR < 3
// <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
#endif
#include "component.h"
#include "client.h"
#include "state.h"
#include "component.h"
#include "message.h"
#include "state.h"
#define WEBSOCKET_LISTEN_PORT 9000
@ -50,10 +50,9 @@ struct LwsPollFdGlibSource {
class WebsocketsServer : public SurfaceComponent
{
public:
public:
WebsocketsServer (ArdourSurface::ArdourWebsockets&);
virtual ~WebsocketsServer () {};
virtual ~WebsocketsServer (){};
int start ();
int stop ();
@ -61,11 +60,10 @@ class WebsocketsServer : public SurfaceComponent
void update_client (Client, const NodeState&, bool);
void update_all_clients (const NodeState&, bool);
private:
private:
struct lws_protocols _lws_proto[2];
struct lws_context_creation_info _lws_info;
struct lws_context *_lws_context;
struct lws_context* _lws_context;
Glib::RefPtr<Glib::IOChannel> _channel;
@ -81,7 +79,7 @@ class WebsocketsServer : public SurfaceComponent
void add_client (Client);
void del_client (Client);
void recv_client (Client, void *buf, size_t len);
void recv_client (Client, void* buf, size_t len);
void write_client (Client);
bool io_handler (Glib::IOCondition, lws_sockfd_type);
@ -89,8 +87,7 @@ class WebsocketsServer : public SurfaceComponent
Glib::IOCondition events_to_ioc (int);
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

View file

@ -16,20 +16,24 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <sstream>
#include <boost/unordered_set.hpp>
#include <sstream>
#include "state.h"
NodeState::NodeState () { }
NodeState::NodeState () {}
NodeState::NodeState (std::string node)
: _node (node) { }
: _node (node)
{
}
NodeState::NodeState (std::string node, AddressVector addr, ValueVector val)
: _node (node)
, _addr (addr)
, _val (val) { }
, _val (val)
{
}
std::string
NodeState::debug_str () const
@ -38,7 +42,8 @@ NodeState::debug_str () const
s << "node = " << _node;
if (!_addr.empty ()) {
s << std::endl << " addr = ";
s << std::endl
<< " addr = ";
for (AddressVector::const_iterator it = _addr.begin (); it != _addr.end (); ++it) {
s << *it << ";";
@ -46,7 +51,8 @@ NodeState::debug_str () const
}
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 ();
@ -55,7 +61,7 @@ NodeState::debug_str () const
int
NodeState::n_addr () const
{
return static_cast<int>(_addr.size ());
return static_cast<int> (_addr.size ());
}
uint32_t
@ -73,7 +79,7 @@ NodeState::add_addr (uint32_t addr)
int
NodeState::n_val () const
{
return static_cast<int>(_val.size ());
return static_cast<int> (_val.size ());
}
TypedValue
@ -107,7 +113,8 @@ NodeState::operator== (const NodeState& other) const
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 ();
}

View file

@ -19,17 +19,18 @@
#ifndef node_state_h
#define node_state_h
#include <stdint.h>
#include <climits>
#include <cmath>
#include <cstring>
#include <stdint.h>
#include <vector>
#include "typed_value.h"
#define ADDR_NONE UINT_MAX
namespace Node {
namespace Node
{
const std::string tempo = "tempo";
const std::string strip_desc = "strip_desc";
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_param_desc = "strip_plugin_param_desc";
const std::string strip_plugin_param_value = "strip_plugin_param_value";
}
} // namespace Node
typedef std::vector<uint32_t> AddressVector;
typedef std::vector<TypedValue> ValueVector;
class NodeState {
public:
class NodeState
{
public:
NodeState ();
NodeState (std::string);
NodeState (std::string, AddressVector, ValueVector = ValueVector());
NodeState (std::string, AddressVector, ValueVector = ValueVector ());
std::string debug_str () const;
std::string node () const { return _node; }
std::string node () const
{
return _node;
}
int n_addr () const;
uint32_t nth_addr (int) const;
@ -69,14 +72,13 @@ class NodeState {
bool operator== (const NodeState& other) const;
private:
private:
std::string _node;
AddressVector _addr;
ValueVector _val;
};
std::size_t hash_value (const NodeState&);
std::size_t
hash_value (const NodeState&);
#endif // node_state_h

View file

@ -16,9 +16,9 @@
* 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/plugin_insert.h"
#include "ardour/session.h"
#include "pbd/controllable.h"
#include "strips.h"
@ -28,7 +28,7 @@ using namespace ARDOUR;
int
ArdourStrips::start ()
{
// take an indexed snapshot of current strips
/* take an indexed snapshot of current strips */
StripableList strips;
session ().get_stripables (strips, PresentationInfo::AllStripables);
@ -53,9 +53,9 @@ ArdourStrips::to_db (double k)
return -std::numeric_limits<double>::infinity ();
}
float db = accurate_coefficient_to_dB (static_cast<float>(k));
float db = accurate_coefficient_to_dB (static_cast<float> (k));
return static_cast<double>(db);
return static_cast<double> (db);
}
double
@ -65,9 +65,9 @@ ArdourStrips::from_db (double db)
return 0;
}
float k = dB_to_coefficient (static_cast<float>(db));
float k = dB_to_coefficient (static_cast<float> (db));
return static_cast<double>(k);
return static_cast<double> (k);
}
double
@ -85,7 +85,7 @@ ArdourStrips::set_strip_gain (uint32_t strip_n, double db)
double
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;
}
@ -143,11 +143,11 @@ ArdourStrips::set_strip_plugin_param_value (uint32_t strip_n, uint32_t plugin_n,
double dbl_val;
if (pd.toggled) {
dbl_val = static_cast<double>(static_cast<bool>(value));
dbl_val = static_cast<double> (static_cast<bool> (value));
} else if (pd.enumeration || pd.integer_step) {
dbl_val = static_cast<double>(static_cast<int>(value));
dbl_val = static_cast<double> (static_cast<int> (value));
} else {
dbl_val = static_cast<double>(value);
dbl_val = static_cast<double> (value);
}
control->set_value (dbl_val, PBD::Controllable::NoGroup);
@ -167,7 +167,7 @@ ArdourStrips::nth_strip (uint32_t strip_n) const
return _strips[strip_n];
}
return boost::shared_ptr<Stripable>();
return boost::shared_ptr<Stripable> ();
}
TypedValue
@ -179,9 +179,9 @@ ArdourStrips::plugin_param_value (boost::shared_ptr<ARDOUR::AutomationControl> c
ParameterDescriptor pd = control->desc ();
if (pd.toggled) {
value = TypedValue (static_cast<bool>(control->get_value ()));
value = TypedValue (static_cast<bool> (control->get_value ()));
} else if (pd.enumeration || pd.integer_step) {
value = TypedValue (static_cast<int>(control->get_value ()));
value = TypedValue (static_cast<int> (control->get_value ()));
} else {
value = TypedValue (control->get_value ());
}
@ -206,7 +206,7 @@ ArdourStrips::strip_plugin_insert (uint32_t strip_n, uint32_t plugin_n) const
}
}
return boost::shared_ptr<PluginInsert>();
return boost::shared_ptr<PluginInsert> ();
}
boost::shared_ptr<AutomationControl>
@ -222,10 +222,10 @@ ArdourStrips::strip_plugin_param_control (uint32_t strip_n, uint32_t plugin_n,
if (ok && plugin->parameter_is_input (control_id)) {
boost::shared_ptr<AutomationControl> control =
insert->automation_control (Evoral::Parameter(PluginAutomation, 0, control_id));
insert->automation_control (Evoral::Parameter (PluginAutomation, 0, control_id));
return control;
}
}
return boost::shared_ptr<AutomationControl>();
return boost::shared_ptr<AutomationControl> ();
}

View file

@ -24,10 +24,10 @@
class ArdourStrips : public SurfaceComponent
{
public:
ArdourStrips (ArdourSurface::ArdourWebsockets& surface) : SurfaceComponent (surface) {};
virtual ~ArdourStrips () {};
public:
ArdourStrips (ArdourSurface::ArdourWebsockets& surface)
: SurfaceComponent (surface){};
virtual ~ArdourStrips (){};
int start ();
int stop ();
@ -55,16 +55,14 @@ class ArdourStrips : public SurfaceComponent
boost::shared_ptr<ARDOUR::PluginInsert> strip_plugin_insert (uint32_t, uint32_t) const;
boost::shared_ptr<ARDOUR::AutomationControl> strip_plugin_param_control(
boost::shared_ptr<ARDOUR::AutomationControl> strip_plugin_param_control (
uint32_t, uint32_t, uint32_t) const;
static TypedValue plugin_param_value (boost::shared_ptr<ARDOUR::AutomationControl>);
private:
private:
typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > StripableVector;
StripableVector _strips;
};
#endif // ardour_strips_h

View file

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

View file

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