13
0

OSC: catch bad commands on /cue/* created crash on exit

This commit is contained in:
Len Ovens 2017-11-07 20:18:23 -08:00
parent 4c58ada24b
commit 3a2c481b96
6 changed files with 61 additions and 74 deletions

View File

@ -363,9 +363,9 @@ OSC::surface_destroy (OSCSurface* sur)
OSCCueObserver* co;
if ((co = dynamic_cast<OSCCueObserver*>(sur->cue_obs)) != 0) {
co->clear_observer ();
delete co;
sur->cue_obs = 0;
sur->sends.clear ();
}
OSCGlobalObserver* go;
@ -1455,11 +1455,10 @@ void
OSC::surface_link_state (LinkSet * set)
{
for (uint32_t dv = 1; dv < set->urls.size(); dv++) {
OSCSurface *sur;
if (set->urls[dv] != "") {
string url = set->urls[dv];
sur = get_surface (lo_address_new_from_url (url.c_str()));
OSCSurface *sur = get_surface (lo_address_new_from_url (url.c_str()));
for (uint32_t i = 0; i < sur->observers.size(); i++) {
sur->observers[i]->set_link_ready (set->not_ready);
}
@ -1484,7 +1483,6 @@ OSC::link_check (uint32_t set)
ls = &link_sets[set];
uint32_t bank_total = 0;
for (uint32_t dv = 1; dv < ls->urls.size(); dv++) {
std::cout << string_compose ("link_check dv %1 banksize: %2\n", dv, bank_total);
OSCSurface *su;
if (ls->urls[dv] != "") {
@ -1494,15 +1492,11 @@ OSC::link_check (uint32_t set)
return dv;
}
if (su->linkset == set) {
std::cout << string_compose ("checking sur %1 %2 banksize %3\n", dv, su->remote_url, su->bank_size);
bank_total = bank_total + su->bank_size;
} else {
std::cout << "dv not ready\n";
ls->urls[dv] = "";
return dv;
}
std::cout << string_compose ("link_checked dv %1 banksize: %2\n", dv, bank_total);
//std::cout << string_compose ("link_check notready %1 banksize: %2\n", set_ready, bank_total);
if (ls->autobank) {
ls->banksize = bank_total;
} else {
@ -5194,19 +5188,28 @@ OSC::get_sorted_stripables(std::bitset<32> types, bool cue)
int
OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo_message msg)
{
OSCSurface *s = get_surface(get_address (msg), true);
s->bank_size = 0;
float value = 0;
int ret = 1; /* unhandled */
if (!strncmp (path, "/cue/aux", 8)) {
// set our Aux bus
if (argv[0]->f) {
ret = cue_set (argv[0]->f, msg);
} else {
ret = 0;
if (argc) {
if (types[0] == 'f') {
value = argv[0]->f;
} else if (types[0] == 'i') {
value = (float) argv[0]->i;
}
if (value) {
ret = cue_set ((uint32_t) argv[0]->f, msg);
} else {
ret = 0;
}
}
}
else if (!strncmp (path, "/cue/connect", 12)) {
// Connect to default Aux bus
if ((!argc) || argv[0]->f) {
if ((!argc) || argv[0]->f || argv[0]->i) {
ret = cue_set (1, msg);
} else {
ret = 0;
@ -5214,7 +5217,7 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
}
else if (!strncmp (path, "/cue/next_aux", 13)) {
// switch to next Aux bus
if ((!argc) || argv[0]->f) {
if ((!argc) || argv[0]->f || argv[0]->i) {
ret = cue_next (msg);
} else {
ret = 0;
@ -5222,25 +5225,33 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
}
else if (!strncmp (path, "/cue/previous_aux", 17)) {
// switch to previous Aux bus
if ((!argc) || argv[0]->f) {
if ((!argc) || argv[0]->f || argv[0]->i) {
ret = cue_previous (msg);
} else {
ret = 0;
}
}
else if (!strncmp (path, "/cue/send/fader/", 16) && strlen (path) > 16) {
int id = atoi (&path[16]);
ret = cue_send_fader (id, argv[0]->f, msg);
if (argc == 1) {
int id = atoi (&path[16]);
ret = cue_send_fader (id, argv[0]->f, msg);
}
}
else if (!strncmp (path, "/cue/send/enable/", 17) && strlen (path) > 17) {
int id = atoi (&path[17]);
ret = cue_send_enable (id, argv[0]->f, msg);
if (argc == 1) {
int id = atoi (&path[17]);
ret = cue_send_enable (id, argv[0]->f, msg);
}
}
else if (!strncmp (path, "/cue/fader", 10)) {
ret = cue_aux_fader (argv[0]->f, msg);
if (argc == 1) {
ret = cue_aux_fader (argv[0]->f, msg);
}
}
else if (!strncmp (path, "/cue/mute", 9)) {
ret = cue_aux_mute (argv[0]->f, msg);
if (argc == 1) {
ret = cue_aux_mute (argv[0]->f, msg);
}
}
return ret;
@ -5249,7 +5260,7 @@ OSC::cue_parse (const char *path, const char* types, lo_arg **argv, int argc, lo
int
OSC::cue_set (uint32_t aux, lo_message msg)
{
set_surface_feedback (0, msg);
return _cue_set (aux, get_address (msg));
}
@ -5257,7 +5268,7 @@ int
OSC::_cue_set (uint32_t aux, lo_address addr)
{
int ret = 1;
OSCSurface *s = get_surface(addr);
OSCSurface *s = get_surface(addr, true);
s->bank_size = 0;
s->strip_types = 128;
s->feedback = 0;
@ -5273,7 +5284,6 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
aux = s->nstrips;
}
s->aux = aux;
// get a list of Auxes
for (uint32_t n = 0; n < s->nstrips; ++n) {
boost::shared_ptr<Stripable> stp = s->strips[n];
@ -5281,13 +5291,12 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
text_message (string_compose ("/cue/name/%1", n+1), stp->name(), addr);
if (aux == n+1) {
// aux must be at least one
// need a signal if aux vanishes
stp->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::_cue_set, this, aux, addr), this);
stp->DropReferences.connect (*this, MISSING_INVALIDATOR, boost::bind (&OSC::_cue_set, this, aux, addr), this);
// make a list of stripables with sends that go to this bus
s->sends = cue_get_sorted_stripables(stp, aux, addr);
if (s->cue_obs) {
s->cue_obs->refresh_strip (false);
s->cue_obs->refresh_strip (stp, s->sends, false);
} else {
// start cue observer
OSCCueObserver* co = new OSCCueObserver (*this, s);
@ -5305,7 +5314,7 @@ OSC::_cue_set (uint32_t aux, lo_address addr)
int
OSC::cue_next (lo_message msg)
{
OSCSurface *s = get_surface(get_address (msg));
OSCSurface *s = get_surface(get_address (msg), true);
int ret = 1;
if (!s->cue) {
@ -5322,7 +5331,7 @@ OSC::cue_next (lo_message msg)
int
OSC::cue_previous (lo_message msg)
{
OSCSurface *s = get_surface(get_address (msg));
OSCSurface *s = get_surface(get_address (msg), true);
int ret = 1;
if (!s->cue) {
ret = cue_set (1, msg);
@ -5336,7 +5345,7 @@ OSC::cue_previous (lo_message msg)
boost::shared_ptr<Send>
OSC::cue_get_send (uint32_t id, lo_address addr)
{
OSCSurface *s = get_surface(addr);
OSCSurface *s = get_surface(addr, true);
if (id && s->aux > 0 && id <= s->sends.size()) {
boost::shared_ptr<Route> r = boost::dynamic_pointer_cast<Route> (s->sends[id - 1]);
boost::shared_ptr<Stripable> aux = get_strip (s->aux, addr);
@ -5353,7 +5362,7 @@ OSC::cue_aux_fader (float position, lo_message msg)
{
if (!session) return -1;
OSCSurface *sur = get_surface(get_address (msg));
OSCSurface *sur = get_surface(get_address (msg), true);
if (sur->cue) {
if (sur->aux) {
boost::shared_ptr<Stripable> s = get_strip (sur->aux, get_address (msg));
@ -5375,7 +5384,7 @@ OSC::cue_aux_mute (float state, lo_message msg)
{
if (!session) return -1;
OSCSurface *sur = get_surface(get_address (msg));
OSCSurface *sur = get_surface(get_address (msg), true);
if (sur->cue) {
if (sur->aux) {
boost::shared_ptr<Stripable> s = get_strip (sur->aux, get_address (msg));

View File

@ -41,13 +41,20 @@ OSCCueObserver::OSCCueObserver (OSC& o, ArdourSurface::OSC::OSCSurface* su)
, tick_enable (false)
{
addr = lo_address_new_from_url (sur->remote_url.c_str());
refresh_strip (true);
uint32_t sid = sur->aux - 1;
if (sid >= sur->strips.size ()) {
sid = 0;
}
_strip = sur->strips[sid];
sends = sur->sends;
refresh_strip (_strip, sends, true);
}
OSCCueObserver::~OSCCueObserver ()
{
tick_enable = false;
no_strip ();
clear_observer ();
lo_address_free (addr);
}
@ -67,41 +74,16 @@ OSCCueObserver::clear_observer ()
}
void
OSCCueObserver::no_strip ()
{
// This gets called on drop references
tick_enable = false;
strip_connections.drop_connections ();
/*
* The strip will sit idle at this point doing nothing until
* the surface has recalculated it's strip list and then calls
* refresh_strip. Otherwise refresh strip will get a strip address
* that does not exist... Crash
*/
}
void
OSCCueObserver::refresh_strip (bool force)
OSCCueObserver::refresh_strip (boost::shared_ptr<ARDOUR::Stripable> new_strip, Sorted new_sends, bool force)
{
tick_enable = false;
uint32_t sid = sur->aux - 1;
if (sid >= sur->strips.size ()) {
sid = 0;
}
boost::shared_ptr<ARDOUR::Stripable> new_strip = sur->strips[sid];
if (_strip && (new_strip == _strip) && !force) {
tick_enable = true;
return;
}
strip_connections.drop_connections ();
send_end ();
_strip = new_strip;
_strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::no_strip, this), OSC::instance());
sends = sur->sends;
_strip->DropReferences.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::clear_observer, this), OSC::instance());
sends = new_sends;
_strip->PropertyChanged.connect (strip_connections, MISSING_INVALIDATOR, boost::bind (&OSCCueObserver::name_changed, this, boost::lambda::_1, 0), OSC::instance());
name_changed (ARDOUR::Properties::name, 0);
@ -199,6 +181,7 @@ OSCCueObserver::send_end ()
}
gain_timeout.clear ();
_last_gain.clear ();
sends.clear ();
}
void
@ -230,7 +213,6 @@ OSCCueObserver::name_changed (const PBD::PropertyChange& what_changed, uint32_t
void
OSCCueObserver::send_change_message (string path, uint32_t id, boost::shared_ptr<Controllable> controllable)
{
// maybe don't need ID only used for mute- maybe mute can use enable
if (id) {
path = string_compose("%1/%2", path, id);
}

View File

@ -42,7 +42,7 @@ class OSCCueObserver
typedef std::vector<boost::shared_ptr<ARDOUR::Stripable> > Sorted;
Sorted sends;
void clear_observer (void);
void refresh_strip (bool force);
void refresh_strip (boost::shared_ptr<ARDOUR::Stripable> new_strip, Sorted new_sends, bool force);
private:
@ -67,7 +67,6 @@ class OSCCueObserver
void send_init (void);
void send_end (void);
void send_restart (void);
void no_strip ();
};
#endif /* __osc_osccueobserver_h__ */

View File

@ -49,7 +49,6 @@ OSCGlobalObserver::OSCGlobalObserver (OSC& o, Session& s, ArdourSurface::OSC::OS
,last_click (4)
{
addr = lo_address_new_from_url (sur->remote_url.c_str());
//addr = lo_address_new (lo_address_get_hostname(a) , lo_address_get_port(a));
session = &s;
gainmode = sur->gainmode;
feedback = sur->feedback;
@ -107,10 +106,6 @@ OSCGlobalObserver::OSCGlobalObserver (OSC& o, Session& s, ArdourSurface::OSC::OS
send_gain_message ("/monitor/", strip->gain_control());
}
/*
* Transport (todo)
* punchin/out
*/
//Transport feedback
session->TransportStateChange.connect(session_connections, MISSING_INVALIDATOR, boost::bind (&OSCGlobalObserver::send_transport_state_changed, this), OSC::instance());
send_transport_state_changed ();

View File

@ -63,6 +63,7 @@ OSCSelectObserver::OSCSelectObserver (OSC& o, ArdourSurface::OSC::OSCSurface* su
feedback = sur->feedback;
in_line = feedback[2];
refresh_strip (true);
send_page_size = sur->send_page_size;
}
OSCSelectObserver::~OSCSelectObserver ()
@ -328,8 +329,8 @@ OSCSelectObserver::send_init()
// paging should be done in osc.cc in case there is no feedback
send_size = nsends;
if (sur->send_page_size) {
send_size = sur->send_page_size;
if (send_page_size) {
send_size = send_page_size;
}
// check limits
uint32_t max_page = (uint32_t)(nsends / send_size) + 1;
@ -559,7 +560,7 @@ OSCSelectObserver::tick ()
for (uint32_t i = 1; i <= send_timeout.size(); i++) {
if (send_timeout[i]) {
if (send_timeout[i] == 1) {
uint32_t pg_offset = (sur->send_page - 1) * sur->send_page_size;
uint32_t pg_offset = (sur->send_page - 1) * send_page_size;
_osc.text_message_with_id ("/select/send_name", i, _strip->send_name(pg_offset + i - 1), in_line, addr);
}
send_timeout[i]--;

View File

@ -75,6 +75,7 @@ class OSCSelectObserver
bool _init;
float _comp_redux;
ARDOUR::AutoState as;
uint32_t send_page_size;
uint32_t send_size;
uint32_t nplug_params;
uint32_t plug_size;