Changeset 1248

Show
Ignore:
Timestamp:
06/09/08 10:21:44 (3 months ago)
Author:
drobilla
Message:

Bump liblo dependency to 0.24.
Bundleify communications where order is relevant (fixes 'random' issues like node positions being off, ticket #89, etc).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • configure.ac

    r1247 r1248  
    289289 
    290290# OSC support (mandatory for now due to laziness) 
    291 PKG_CHECK_MODULES(LIBLO, liblo
     291PKG_CHECK_MODULES(LIBLO, liblo >= 0.24
    292292 
    293293# LV2 support 
  • ingen/configure.ac

    r1245 r1248  
    141141 
    142142# OSC support (mandatory for now due to laziness) 
    143 PKG_CHECK_MODULES(LIBLO, liblo
     143PKG_CHECK_MODULES(LIBLO, liblo >= 0.24
    144144 
    145145# LV2 support 
  • ingen/src/libs/client/OSCClientReceiver.cpp

    r1218 r1248  
    3232         
    3333OSCClientReceiver::OSCClientReceiver(int listen_port) 
    34 : ClientInterface("localhost"), 
    35   _listen_port(listen_port), 
    36  _st(NULL) 
     34        : ClientInterface("localhost") 
     35        , _listen_port(listen_port) 
     36       , _st(NULL) 
    3737{ 
    3838        start(false); // true = dump, false = shutup 
  • ingen/src/libs/engine/ClientBroadcaster.cpp

    r898 r1248  
    9292} 
    9393 
     94         
     95void 
     96ClientBroadcaster::bundle_begin() 
     97{ 
     98        for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) 
     99                (*i).second->bundle_begin(); 
     100} 
     101 
     102         
     103void 
     104ClientBroadcaster::bundle_end() 
     105{ 
     106        for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) 
     107                (*i).second->bundle_end(); 
     108} 
     109 
    94110 
    95111void 
  • ingen/src/libs/engine/ClientBroadcaster.hpp

    r876 r1248  
    6161        //void send_client_registration(const string& url, int client_id); 
    6262         
     63        void bundle_begin(); 
     64        void bundle_end(); 
     65         
    6366        // Error that isn't the direct result of a request 
    6467        void send_error(const string& msg); 
  • ingen/src/libs/engine/events/DestroyEvent.cpp

    r1225 r1248  
    183183                _node->deactivate(); 
    184184                _responder->respond_ok(); 
     185                _engine.broadcaster()->bundle_begin(); 
    185186                if (_disconnect_node_event) 
    186187                        _disconnect_node_event->post_process(); 
    187188                _engine.broadcaster()->send_destroyed(_path); 
     189                _engine.broadcaster()->bundle_end(); 
    188190                _engine.maid()->push(_patch_node_listnode); 
    189191        } else if (_patch_port_listnode) {       
    190192                assert(_port); 
    191193                _responder->respond_ok(); 
     194                _engine.broadcaster()->bundle_begin(); 
    192195                if (_disconnect_port_event) 
    193196                        _disconnect_port_event->post_process(); 
    194197                _engine.broadcaster()->send_destroyed(_path); 
     198                _engine.broadcaster()->bundle_end(); 
    195199                _engine.maid()->push(_patch_port_listnode); 
    196200        } else { 
  • ingen/src/libs/engine/ObjectSender.cpp

    r1113 r1248  
    3434ObjectSender::send_patch(ClientInterface* client, const PatchImpl* patch, bool recursive) 
    3535{ 
     36        client->bundle_begin(); 
     37 
    3638        client->new_patch(patch->path(), patch->internal_polyphony()); 
    3739        client->polyphonic(patch->path(), patch->polyphonic()); 
     40         
     41        // Send variable 
     42        const GraphObjectImpl::Variables& data = patch->variables(); 
     43        for (GraphObjectImpl::Variables::const_iterator j = data.begin(); j != data.end(); ++j) 
     44                client->variable_change(patch->path(), (*j).first, (*j).second); 
     45         
     46        if (patch->enabled()) 
     47                client->patch_enabled(patch->path()); 
     48 
     49        client->bundle_end(); 
    3850         
    3951        if (recursive) { 
     
    6173 
    6274        } 
    63  
    64         // Send variable 
    65         const GraphObjectImpl::Variables& data = patch->variables(); 
    66         for (GraphObjectImpl::Variables::const_iterator j = data.begin(); j != data.end(); ++j) 
    67                 client->variable_change(patch->path(), (*j).first, (*j).second); 
    68          
    69         if (patch->enabled()) 
    70                 client->patch_enabled(patch->path()); 
    7175} 
    7276 
  • ingen/src/libs/engine/OSCClientSender.cpp

    r1113 r1248  
    3939OSCClientSender::bundle_begin() 
    4040{ 
    41         // FIXME: Don't split bundles as for 'transfers' 
     41        assert(!_transfer); 
    4242        _transfer = lo_bundle_new(LO_TT_IMMEDIATE); 
     43        _send_state = SendingBundle; 
     44 
    4345} 
    4446 
     
    4648OSCClientSender::bundle_end() 
    4749{ 
    48         // FIXME: Don't split bundles as for 'transfers' 
    4950        transfer_end(); 
    5051} 
     
    5455OSCClientSender::transfer_begin() 
    5556{ 
     57        //cerr << "TRANSFER {" << endl; 
     58        assert(!_transfer); 
    5659        _transfer = lo_bundle_new(LO_TT_IMMEDIATE); 
     60        _send_state = SendingTransfer; 
    5761} 
    5862 
     
    6165OSCClientSender::transfer_end() 
    6266{ 
     67        //cerr << "} TRANSFER" << endl; 
    6368        assert(_transfer); 
    6469        lo_send_bundle(_address, _transfer); 
    6570        lo_bundle_free(_transfer); 
    6671        _transfer = NULL; 
    67 
     72        _send_state = Immediate; 
     73
     74 
     75 
     76int 
     77OSCClientSender::send(const char *path, const char *types, ...) 
     78
     79        if (!_enabled) 
     80                return 0; 
     81 
     82        va_list args; 
     83        va_start(args, types); 
     84         
     85        lo_message msg = lo_message_new(); 
     86        int ret = lo_message_add_varargs(msg, types, args); 
     87     
     88        if (!ret) 
     89                send_message(path, msg); 
     90     
     91        va_end(args); 
     92 
     93        return ret; 
     94
     95 
     96 
     97void 
     98OSCClientSender::send_message(const char* path, lo_message msg) 
     99
     100        // FIXME: size?  liblo doesn't export this. 
     101        // Don't want to exceed max UDP packet size (1500 bytes?}) 
     102        static const size_t MAX_BUNDLE_SIZE = 1500 - 32*5; 
     103 
     104        if (!_enabled) 
     105                return; 
     106                 
     107        if (_transfer) { 
     108                if (lo_bundle_length(_transfer) + lo_message_length(msg, path) > MAX_BUNDLE_SIZE) { 
     109                        if (_send_state == SendingBundle) 
     110                                cerr << "WARNING: Maximum bundle size reached, bundle split" << endl; 
     111                        lo_send_bundle(_address, _transfer); 
     112                        _transfer = lo_bundle_new(LO_TT_IMMEDIATE); 
     113                } 
     114                lo_bundle_add_message(_transfer, path, msg); 
     115 
     116        } else { 
     117                lo_send_message(_address, path, msg); 
     118        } 
     119
     120 
    68121 
    69122 
     
    150203OSCClientSender::error(const std::string& msg) 
    151204{ 
    152         if (!_enabled) 
    153                 return; 
    154  
    155         lo_send(_address, "/ingen/error", "s", msg.c_str()); 
     205        send("/ingen/error", "s", msg.c_str(), LO_ARGS_END); 
    156206} 
    157207 
     
    174224OSCClientSender::num_plugins(uint32_t num) 
    175225{ 
    176         if (!_enabled) 
    177                 return; 
    178  
    179         lo_message m = lo_message_new(); 
    180         lo_message_add_int32(m, num); 
    181         lo_send_message(_address, "/ingen/num_plugins", m); 
     226        send("/ingen/num_plugins", "i", num, LO_ARGS_END); 
    182227} 
    183228 
     
    256301                               uint32_t             num_ports) 
    257302{ 
    258         if (!_enabled) 
    259                 return; 
    260  
    261303        if (is_polyphonic) 
    262                 lo_send(_address, "/ingen/new_node", "ssTi", plugin_uri.c_str(), 
    263                         node_path.c_str(), num_ports); 
     304                send("/ingen/new_node", "ssTi", plugin_uri.c_str(), 
     305                        node_path.c_str(), num_ports, LO_ARGS_END); 
    264306        else 
    265                 lo_send(_address, "/ingen/new_node", "ssFi", plugin_uri.c_str(), 
    266                         node_path.c_str(), num_ports); 
     307                send("/ingen/new_node", "ssFi", plugin_uri.c_str(), 
     308                        node_path.c_str(), num_ports, LO_ARGS_END); 
    267309} 
    268310 
     
    290332                          bool               is_output) 
    291333{ 
    292         if (!_enabled) 
    293                 return; 
    294  
    295         lo_send(_address, "/ingen/new_port", "sisi", path.c_str(), index, data_type.c_str(), is_output); 
     334        send("/ingen/new_port", "sisi", path.c_str(), index, data_type.c_str(), is_output, LO_ARGS_END); 
    296335} 
    297336 
     
    328367OSCClientSender::object_destroyed(const std::string& path) 
    329368{ 
    330         if (!_enabled) 
    331                 return; 
    332  
    333369        assert(path != "/"); 
    334370         
    335         lo_send(_address, "/ingen/destroyed", "s", path.c_str()); 
     371        send("/ingen/destroyed", "s", path.c_str(), LO_ARGS_END); 
    336372} 
    337373 
     
    344380OSCClientSender::patch_cleared(const std::string& patch_path) 
    345381{ 
    346         if (!_enabled) 
    347                 return; 
    348  
    349         lo_send(_address, "/ingen/patch_cleared", "s", patch_path.c_str()); 
     382        send("/ingen/patch_cleared", "s", patch_path.c_str(), LO_ARGS_END); 
    350383} 
    351384 
     
    358391OSCClientSender::patch_enabled(const std::string& patch_path) 
    359392{ 
    360         if (!_enabled) 
    361                 return; 
    362  
    363         lo_send(_address, "/ingen/patch_enabled", "s", patch_path.c_str()); 
     393        send("/ingen/patch_enabled", "s", patch_path.c_str(), LO_ARGS_END); 
    364394} 
    365395 
     
    372402OSCClientSender::patch_disabled(const std::string& patch_path) 
    373403{ 
    374         if (!_enabled) 
    375                 return; 
    376  
    377         lo_send(_address, "/ingen/patch_disabled", "s", patch_path.c_str()); 
     404        send("/ingen/patch_disabled", "s", patch_path.c_str(), LO_ARGS_END); 
    378405} 
    379406 
     
    402429OSCClientSender::connection(const std::string& src_port_path, const std::string& dst_port_path) 
    403430{ 
    404         if (!_enabled) 
    405                 return; 
    406  
    407         lo_send(_address, "/ingen/new_connection", "ss", src_port_path.c_str(), dst_port_path.c_str()); 
     431        send("/ingen/new_connection", "ss", src_port_path.c_str(), dst_port_path.c_str(), LO_ARGS_END); 
    408432} 
    409433 
     
    417441OSCClientSender::disconnection(const std::string& src_port_path, const std::string& dst_port_path) 
    418442{ 
    419         if (!_enabled) 
    420                 return; 
    421  
    422         lo_send(_address, "/ingen/disconnection", "ss", src_port_path.c_str(), dst_port_path.c_str()); 
     443        send("/ingen/disconnection", "ss", src_port_path.c_str(), dst_port_path.c_str(), LO_ARGS_END); 
    423444} 
    424445 
     
    433454OSCClientSender::variable_change(const std::string& path, const std::string& key, const Atom& value) 
    434455{ 
    435         if (!_enabled) 
    436                 return; 
    437  
    438456        lo_message m = lo_message_new(); 
    439457        lo_message_add_string(m, path.c_str()); 
    440458        lo_message_add_string(m, key.c_str()); 
    441459        Raul::AtomLiblo::lo_message_add_atom(m, value); 
    442         lo_send_message(_address, "/ingen/variable_change", m); 
     460        send_message("/ingen/variable_change", m); 
    443461} 
    444462 
     
    452470OSCClientSender::control_change(const std::string& port_path, float value) 
    453471{ 
    454         if (!_enabled) 
    455                 return; 
    456  
    457         lo_send(_address, "/ingen/control_change", "sf", port_path.c_str(), value); 
     472        send("/ingen/control_change", "sf", port_path.c_str(), value, LO_ARGS_END); 
    458473} 
    459474 
     
    486501                            const std::string& name) 
    487502{ 
    488         if (!_enabled) 
    489                 return; 
    490  
    491503        // FIXME: size?  liblo doesn't export this. 
    492504        // Don't want to exceed max UDP packet size (1500 bytes) 
     
    522534OSCClientSender::new_patch(const std::string& path, uint32_t poly) 
    523535{ 
    524         if (!_enabled) 
    525                 return; 
    526  
    527         lo_send(_address, "/ingen/new_patch", "si", path.c_str(), poly); 
     536        send("/ingen/new_patch", "si", path.c_str(), poly, LO_ARGS_END); 
    528537         
    529538        /* 
     
    548557OSCClientSender::object_renamed(const std::string& old_path, const std::string& new_path) 
    549558{ 
    550         if (!_enabled) 
    551                 return; 
    552  
    553         lo_send(_address, "/ingen/object_renamed", "ss", old_path.c_str(), new_path.c_str()); 
     559        send("/ingen/object_renamed", "ss", old_path.c_str(), new_path.c_str(), LO_ARGS_END); 
    554560} 
    555561 
     
    560566OSCClientSender::program_add(const std::string& node_path, uint32_t bank, uint32_t program, const std::string& name) 
    561567{ 
    562         if (!_enabled) 
    563                 return; 
    564  
    565         lo_send(_address, "/ingen/program_add", "siis",  
     568        send("/ingen/program_add", "siis",  
    566569                node_path.c_str(), bank, program, name.c_str()); 
    567570} 
     
    571574OSCClientSender::program_remove(const std::string& node_path, uint32_t bank, uint32_t program) 
    572575{ 
    573         if (!_enabled) 
    574                 return; 
    575  
    576         lo_send(_address, "/ingen/program_remove", "sii",  
     576        send("/ingen/program_remove", "sii",  
    577577                node_path.c_str(), bank, program); 
    578578} 
  • ingen/src/libs/engine/OSCClientSender.hpp

    r1191 r1248  
    135135 
    136136private: 
     137        int  send(const char *path, const char *types, ...); 
     138        void send_message(const char* path, lo_message m); 
     139 
     140        enum SendState { Immediate, SendingBundle, SendingTransfer }; 
     141 
     142        string     _url; 
    137143        lo_address _address; 
    138  
    139         lo_bundle _transfer; 
    140  
    141         bool _enabled; 
     144        SendState  _send_state; 
     145        lo_bundle  _transfer; 
     146        bool       _enabled; 
    142147}; 
    143148