├── .gitignore ├── src ├── liveTrack.h ├── liveDevice.h ├── liveClip.h ├── liveClipSlot.h ├── liveObject.h ├── liveTrack.cpp ├── liveParam.h ├── liveConnection.h ├── liveDevice.cpp ├── liveClipSlot.cpp ├── liveObject.cpp ├── liveSet.h ├── liveClip.cpp ├── liveParam.cpp ├── ofxAbleton.h ├── liveConnection.cpp └── liveSet.cpp ├── openFrameworks-Info.plist └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build 3 | build/* 4 | bin 5 | bin/* 6 | ofxAbleton.xcodeproj 7 | ofxAbleton.xcodeproj/* 8 | -------------------------------------------------------------------------------- /src/liveTrack.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_TRACK 2 | #define _LIVE_TRACK 3 | 4 | #include "liveObject.h" 5 | #include "liveClipSlot.h" 6 | 7 | class liveTrack: public liveObject { 8 | 9 | public: 10 | liveTrack(liveSet* _parent_set, int _order, string _name); 11 | 12 | int order; 13 | string name; 14 | 15 | }; 16 | 17 | #endif -------------------------------------------------------------------------------- /src/liveDevice.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_DEVICE 2 | #define _LIVE_DEVICE 3 | 4 | #include "liveObject.h" 5 | 6 | class liveDevice: public liveObject { 7 | 8 | public: 9 | liveDevice(liveSet* _parent_set, int _track_order, int _order, string name); 10 | string getName(); 11 | int getTrackOrder(); 12 | int getOrder(); 13 | 14 | int track_order; 15 | int order; 16 | string name; 17 | 18 | }; 19 | 20 | #endif -------------------------------------------------------------------------------- /src/liveClip.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_CLIP 2 | #define _LIVE_CLIP 3 | 4 | #include "liveObject.h" 5 | 6 | class liveClip: public liveObject { 7 | 8 | public: 9 | liveClip(liveSet* _parent_set, int _track_order, int _order, string name); 10 | string getName(); 11 | int getTrackOrder(); 12 | int getOrder(); 13 | void fire(); 14 | 15 | int track_order; 16 | int order; 17 | string name; 18 | 19 | }; 20 | 21 | #endif -------------------------------------------------------------------------------- /src/liveClipSlot.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_CLIP_SLOT 2 | #define _LIVE_CLIP_SLOT 3 | 4 | #include "liveObject.h" 5 | #include "liveClip.h" 6 | 7 | class liveClipSlot: public liveObject { 8 | 9 | public: 10 | liveClipSlot(liveSet* _parent_set, int _live_id, int _track_id, int _order, int _track_order); 11 | void getClip(); 12 | 13 | int track_id; 14 | int order; 15 | int track_order; 16 | bool has_clip; 17 | 18 | liveClip* clip; 19 | 20 | }; 21 | 22 | #endif -------------------------------------------------------------------------------- /src/liveObject.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_OBJECT 2 | #define _LIVE_OBJECT 3 | 4 | #include "liveConnection.h" 5 | 6 | class liveSet; 7 | 8 | class liveObject { 9 | 10 | public: 11 | void setPath(); 12 | string getAttr(string _property); 13 | void setAttr(string _property, string _value); 14 | void callFunction(string _function); 15 | int getLiveId(); 16 | int msleep(unsigned long milisec); 17 | 18 | liveSet* parent_set; 19 | int live_id; 20 | 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /src/liveTrack.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveTrack.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/20/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveTrack.h" 11 | #include "liveSet.h" 12 | 13 | liveTrack::liveTrack(liveSet* _parent_set, int _order, string _name) { 14 | parent_set = _parent_set; 15 | order = _order; 16 | name = _name; 17 | 18 | cout << "liveTrack( order: " << _order << ", name: " << name << endl; 19 | } -------------------------------------------------------------------------------- /src/liveParam.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_PARAM 2 | #define _LIVE_PARAM 3 | 4 | #include "liveObject.h" 5 | 6 | class liveParam: public liveObject { 7 | 8 | public: 9 | liveParam(liveSet* _parent_set, int _track_order, int _device_order, int _order, float _val, string _name); 10 | string getName(); 11 | int getTrackOrder(); 12 | int getOrder(); 13 | void setVal(float _val); 14 | 15 | int track_order; 16 | int device_order; 17 | int order; 18 | float val; 19 | string name; 20 | 21 | }; 22 | 23 | #endif -------------------------------------------------------------------------------- /openFrameworks-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | com.yourcompany.openFrameworks 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | APPL 15 | CFBundleSignature 16 | ???? 17 | CFBundleVersion 18 | 1.0 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/liveConnection.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_CONNECTION 2 | #define _LIVE_CONNECTION 3 | 4 | #include "ofMain.h" 5 | #include "ofxOsc.h" 6 | 7 | #define HOST "localhost" 8 | //#define SEND_PORT 7402 9 | //#define RECIEVE_PORT 7403 10 | #define NUM_STEPS 32 11 | #define NUM_BEATS 4 12 | 13 | class liveConnection { 14 | 15 | public: 16 | 17 | liveConnection(); 18 | void recieveData(); 19 | void update(); 20 | void play(); 21 | void stop(); 22 | void setMode(string _mode); 23 | void handleTransport(int _beat); 24 | int live_path(string arg); 25 | void sendMessage(string address, string arg); 26 | string sendMessageWithCallback(string address, string arg); 27 | string recieveStringData(); 28 | int getBeat(); 29 | int getStep(); 30 | 31 | ofxOscSender sender; 32 | ofxOscReceiver receiver; 33 | int int_buffer; 34 | vector message_que; 35 | bool playing; 36 | string mode; 37 | int beat; 38 | int step; 39 | 40 | }; 41 | 42 | #endif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ofxAbleton # 2 | 3 | An Open Frameworks / C++ wrapper for communicating with Ableton Live via OSC. 4 | 5 | 6 | ## Author ## 7 | 8 | Peter Marks (petertmarks [at] gmail [dot] com) 9 | 10 | 11 | ## Status ## 12 | 13 | This is an immature library that's not being actively developed by the original author. I'm not currently using Open Frameworks, but have been asked to provide further documentation for this code. Hopefully it will be of use to someone who wants to integrate Open Frameworks with Ableton, but its by no means a complete solution. 14 | 15 | 16 | ## Dependancies ## 17 | 18 | + [Live OSC](http://liine.net/livecontrol/ableton-liveapi/liveosc/) 19 | 20 | 21 | ## Usage ## 22 | 23 | > new liveSet; 24 | => Scans current live set, copies set info, track info, clip info, device info and device param info into C++ objects of type liveSet, liveTrack, liveClip, liveDevice and liveParam. 25 | 26 | > liveSet->play(); 27 | => Plays current live set 28 | 29 | > liveSet->clips; 30 | => Returns vector containing liveClip objects 31 | 32 | > liveClip->fire(); 33 | => fires selected clip object 34 | 35 | > liveParam->setVal(0.5) 36 | => Set the vale of a param object. -------------------------------------------------------------------------------- /src/liveDevice.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveDevice.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/20/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveDevice.h" 11 | #include "liveSet.h" 12 | 13 | //-------------------------------------------------------------- 14 | liveDevice::liveDevice(liveSet* _parent_set, int _track_order, int _order, string _name){ 15 | parent_set = _parent_set; 16 | track_order = _track_order; 17 | order = _order; 18 | name = _name; 19 | 20 | cout << "liveDevice( track_order: " << track_order << ", order: " << order << ", name: " << name << ")" << endl; 21 | 22 | // Get params 23 | ofxOscMessage m; 24 | m.setAddress( "/live/device" ); 25 | m.addIntArg(track_order); 26 | m.addIntArg(order); 27 | parent_set->sendMessage( m ); 28 | } 29 | 30 | 31 | //-------------------------------------------------------------- 32 | string liveDevice::getName(){ 33 | return name; 34 | } 35 | 36 | 37 | //-------------------------------------------------------------- 38 | int liveDevice::getTrackOrder(){ 39 | return track_order; 40 | } 41 | 42 | 43 | //-------------------------------------------------------------- 44 | int liveDevice::getOrder(){ 45 | return order; 46 | } -------------------------------------------------------------------------------- /src/liveClipSlot.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveClipSlot.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/20/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveClipSlot.h" 11 | #include "liveSet.h" 12 | 13 | liveClipSlot::liveClipSlot(liveSet* _parent_set, int _live_id, int _track_id, int _order, int _track_order){ 14 | parent_set = _parent_set; 15 | live_id = _live_id; 16 | track_id = _track_id; 17 | order = _order; 18 | track_order = _track_order; 19 | has_clip = ofToInt( getAttr("has_clip") ); 20 | 21 | cout << "liveClipSlot( live_id: " << live_id << ", has_clip: " << has_clip << ", track_id: " << track_id << ", order: " << order << ")" << endl; 22 | 23 | getClip(); 24 | } 25 | 26 | 27 | // get the clip if it exists. 28 | void liveClipSlot::getClip(){ 29 | 30 | // // Weird hackish bs 31 | // int new_order = order -1; 32 | // if (new_order == -1) { 33 | // new_order = 0; 34 | // } 35 | // 36 | // if (has_clip) { 37 | // string clip_path = "goto live_set tracks " + ofToString(track_order) + " clip_slots " + ofToString(new_order) + " clip"; 38 | // //cout << "-clip_path: " << clip_path << endl; 39 | // int clip_id = connection->live_path(clip_path); 40 | // clip = new liveClip(parent_set, clip_id, live_id); 41 | // } 42 | } -------------------------------------------------------------------------------- /src/liveObject.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveObject.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/20/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveObject.h" 11 | #include "liveSet.h" 12 | 13 | void liveObject::setPath(){ 14 | // connection->sendMessage("/set_live_object", "id " + ofToString(live_id)); 15 | } 16 | 17 | string liveObject::getAttr(string _property){ 18 | // setPath(); 19 | // msleep(50); 20 | // //cout << "get_attr: " << _property << endl; 21 | // return connection->sendMessageWithCallback("/live_object", "get " + _property); 22 | } 23 | 24 | void liveObject::setAttr(string _property, string _value){ 25 | cout << "set_attr" << endl; 26 | } 27 | 28 | void liveObject::callFunction(string _function) { 29 | // setPath(); 30 | // msleep(50); 31 | // connection->sendMessage("/live_object", "call " + _function); 32 | } 33 | 34 | int liveObject::getLiveId(){ 35 | return live_id; 36 | } 37 | 38 | 39 | // http://cc.byexamples.com/2007/05/25/nanosleep-is-better-than-sleep-and-usleep/ 40 | int liveObject::msleep(unsigned long milisec) 41 | { 42 | struct timespec req={0}; 43 | time_t sec=(int)(milisec/1000); 44 | milisec=milisec-(sec*1000); 45 | req.tv_sec=sec; 46 | req.tv_nsec=milisec*1000000L; 47 | while(nanosleep(&req,&req)==-1) 48 | continue; 49 | return 1; 50 | } 51 | -------------------------------------------------------------------------------- /src/liveSet.h: -------------------------------------------------------------------------------- 1 | #ifndef _LIVE_SET 2 | #define _LIVE_SET 3 | 4 | #include "ofMain.h" 5 | #include "liveTrack.h" 6 | #include "liveClip.h" 7 | #include "liveDevice.h" 8 | #include "liveParam.h" 9 | #include "liveClipSlot.h" 10 | #include "liveObject.h" 11 | #include "ofxOsc.h" 12 | 13 | #define HOST "localhost" 14 | #define SEND_PORT 9000 15 | #define RECIEVE_PORT 9001 16 | #define NUM_STEPS 32 17 | #define FRAME_RATE 60 18 | 19 | // Forward declarations 20 | class liveClip; 21 | class liveObject; 22 | class liveDevice; 23 | class liveParam; 24 | 25 | class liveSet { 26 | //class liveSet: public liveObject { 27 | 28 | public: 29 | liveSet(); 30 | void update(); 31 | void recieveData(); 32 | void play(); 33 | void stop(); 34 | void getInfo(); 35 | void getTracks(); 36 | void getClips(); 37 | void getDevices(); 38 | liveClip * getClipByName(string name, int track_order); 39 | liveParam* getParamByName(string name, int track_order); 40 | int getBeat(); 41 | int getStep(); 42 | bool getPlaying(); 43 | void sendMessage(ofxOscMessage message); 44 | void setCrossfader(float val); 45 | 46 | ofxOscSender sender; 47 | ofxOscReceiver receiver; 48 | bool playing; 49 | float tempo; 50 | int beat; 51 | int step; 52 | vector tracks; 53 | vector clips; 54 | vector devices; 55 | vector params; 56 | 57 | }; 58 | 59 | #endif -------------------------------------------------------------------------------- /src/liveClip.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveClip.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/20/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveClip.h" 11 | #include "liveSet.h" 12 | 13 | //-------------------------------------------------------------- 14 | liveClip::liveClip(liveSet* _parent_set, int _track_order, int _order, string _name){ 15 | parent_set = _parent_set; 16 | track_order = _track_order; 17 | order = _order; 18 | name = _name; 19 | 20 | cout << "liveClip( track_order: " << track_order << ", order: " << order << ", name: " << name << ")" << endl; 21 | } 22 | 23 | 24 | //-------------------------------------------------------------- 25 | string liveClip::getName(){ 26 | return name; 27 | } 28 | 29 | 30 | //-------------------------------------------------------------- 31 | int liveClip::getTrackOrder(){ 32 | return track_order; 33 | } 34 | 35 | 36 | //-------------------------------------------------------------- 37 | int liveClip::getOrder(){ 38 | return order; 39 | } 40 | 41 | 42 | //-------------------------------------------------------------- 43 | void liveClip::fire() { 44 | // /live/play/clip (int track, int clip) 45 | ofxOscMessage m; 46 | m.setAddress( "/live/play/clip" ); 47 | m.addIntArg(track_order); 48 | m.addIntArg(order); 49 | parent_set->sendMessage( m ); 50 | } -------------------------------------------------------------------------------- /src/liveParam.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveDevice.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/20/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveParam.h" 11 | #include "liveSet.h" 12 | 13 | //-------------------------------------------------------------- 14 | liveParam::liveParam(liveSet* _parent_set, int _track_order, int _device_order, int _order, float _val, string _name){ 15 | parent_set = _parent_set; 16 | track_order = _track_order; 17 | device_order = _device_order; 18 | order = _order; 19 | val = _val; 20 | name = _name; 21 | 22 | //setVal(0.5); 23 | 24 | cout << "liveParam( track_order: " << track_order << ", device_order: " << device_order << ", order: " << order << ", val: " << val << ", name: " << name << ")" << endl; 25 | } 26 | 27 | 28 | //-------------------------------------------------------------- 29 | string liveParam::getName(){ 30 | return name; 31 | } 32 | 33 | 34 | //-------------------------------------------------------------- 35 | int liveParam::getTrackOrder(){ 36 | return track_order; 37 | } 38 | 39 | 40 | //-------------------------------------------------------------- 41 | int liveParam::getOrder(){ 42 | return order; 43 | } 44 | 45 | void liveParam::setVal(float _val) { 46 | if (name == "GainLo") { 47 | val = _val * 0.85; 48 | } else { 49 | val = _val; 50 | } 51 | 52 | ofxOscMessage m; 53 | m.setAddress( "/live/device" ); 54 | m.addIntArg(track_order); 55 | m.addIntArg(device_order); 56 | m.addIntArg(order); 57 | m.addFloatArg(val); 58 | parent_set->sendMessage( m ); 59 | } -------------------------------------------------------------------------------- /src/ofxAbleton.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Copyright (c) 2010, Peter Marks 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | * Redistributions of source code must retain the above copyright 9 | notice, this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the distribution. 13 | * Neither the name of the developer nor the 14 | names of its contributors may be used to endorse or promote products 15 | derived from this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY PETER MARKS ''AS IS'' AND ANY 18 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL PETER MARKS BE LIABLE FOR ANY 21 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _OFXABLETON_H 30 | #define _OFXABLETON_H 31 | 32 | #include "liveSet.h" 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/liveConnection.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveConnection.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/19/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveConnection.h" 11 | 12 | liveConnection::liveConnection() { 13 | 14 | // open an outgoing connection to HOST:PORT 15 | // sender.setup( HOST, SEND_PORT ); 16 | // 17 | // // listen on the given port 18 | // receiver.setup( RECIEVE_PORT ); 19 | 20 | // set defaults 21 | int_buffer = 0; 22 | playing = false; 23 | beat = 0; 24 | step = 0; 25 | mode = "scan"; // "scan", "live" 26 | } 27 | 28 | 29 | //-------------------------------------------------------- 30 | // Call once per frame (60 times/sec) 31 | void liveConnection::update() { 32 | 33 | // Increment step 34 | if (playing == true) { 35 | step ++; 36 | if (step == NUM_STEPS) { 37 | step = 0; 38 | } 39 | } 40 | 41 | // send first message in que 42 | if (message_que.size() > 0) { 43 | for (int i=0; i= 0 and playing == true ) { 103 | beat = _beat; 104 | step = 0; 105 | } 106 | } 107 | 108 | 109 | 110 | //-------------------------------------------------------- 111 | int liveConnection::live_path(string arg){ 112 | 113 | ofxOscMessage m; 114 | m.setAddress( "/live_path" ); 115 | m.addStringArg(arg); 116 | sender.sendMessage( m ); 117 | 118 | while (int_buffer == 0) { 119 | recieveData(); 120 | sleep(0.1); 121 | //cout << "sleep..." << endl; 122 | } 123 | int return_int = int_buffer; 124 | int_buffer = 0; 125 | return return_int; 126 | } 127 | 128 | 129 | //-------------------------------------------------------- 130 | void liveConnection::sendMessage(string address, string arg) { 131 | ofxOscMessage m; 132 | m.setAddress( address ); 133 | m.addStringArg(arg); 134 | 135 | // send or que depending on mode 136 | if (mode == "scan") { 137 | sender.sendMessage( m ); 138 | } else if (mode == "live") { 139 | //message_que.insert( message_que.end(), m); 140 | message_que.push_back(m); 141 | //cout << "message_que.size(): " << message_que.size() << endl; 142 | } 143 | } 144 | 145 | 146 | //-------------------------------------------------------- 147 | string liveConnection::sendMessageWithCallback(string address, string arg) { 148 | ofxOscMessage m; 149 | m.setAddress( address ); 150 | m.addStringArg(arg); 151 | sender.sendMessage( m ); 152 | 153 | return recieveStringData(); 154 | } 155 | 156 | 157 | //-------------------------------------------------------- 158 | // Used in callback 159 | string liveConnection::recieveStringData() { 160 | string buffer = "test"; 161 | while (buffer == "test") { 162 | while( receiver.hasWaitingMessages() ) { 163 | ofxOscMessage m; 164 | receiver.getNextMessage( &m ); 165 | int i = 1; 166 | if ( m.getAddress() == "/slot1" ) { 167 | if( m.getArgType( i ) == OFXOSC_TYPE_INT32 ) 168 | buffer = ofToString( m.getArgAsInt32( i ) ); 169 | else if( m.getArgType( i ) == OFXOSC_TYPE_STRING ) 170 | buffer = m.getArgAsString( i ); 171 | } 172 | } 173 | sleep(0.1); 174 | //cout << "sleep..." << endl; 175 | } 176 | return buffer; 177 | } 178 | 179 | 180 | //-------------------------------------------------------------- 181 | int liveConnection::getBeat() { 182 | return beat; 183 | } 184 | 185 | 186 | //-------------------------------------------------------------- 187 | int liveConnection::getStep() { 188 | return step; 189 | } 190 | -------------------------------------------------------------------------------- /src/liveSet.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * liveSet.cpp 3 | * ofxAbleton 4 | * 5 | * Created by Peter Marks on 6/19/10. 6 | * Copyright 2010 __MyCompanyName__. All rights reserved. 7 | * 8 | */ 9 | 10 | #include "liveSet.h" 11 | 12 | //-------------------------------------------------------- 13 | liveSet::liveSet(){ 14 | 15 | cout << "@ " << endl; 16 | 17 | // open an outgoing connection to HOST:PORT 18 | sender.setup( HOST, SEND_PORT ); 19 | 20 | // listen on the given port 21 | receiver.setup( RECIEVE_PORT ); 22 | 23 | // Set defaults 24 | playing = false; 25 | beat = 0; 26 | step = 0; 27 | 28 | // Scan for tracks and clips 29 | getInfo(); 30 | getTracks(); 31 | getClips(); 32 | getDevices(); 33 | 34 | sleep(1); 35 | recieveData(); 36 | 37 | cout << "!!initialized" << endl; 38 | 39 | //setCrossfader(0.8); 40 | 41 | } 42 | 43 | 44 | //-------------------------------------------------------- 45 | void liveSet::update(){ 46 | 47 | // Increment step 48 | if (playing == true) { 49 | step ++; // Need to advance in proportion to tempo 50 | if (step == NUM_STEPS) { 51 | step = 0; 52 | beat ++; 53 | } 54 | } 55 | 56 | // get messages 57 | recieveData(); 58 | } 59 | 60 | 61 | //-------------------------------------------------------- 62 | // Handle incoming OSC messages 63 | void liveSet::recieveData() { 64 | while( receiver.hasWaitingMessages() ) { 65 | ofxOscMessage m; 66 | receiver.getNextMessage( &m ); 67 | 68 | // cout << "@: " << m.getAddress() << endl; 69 | 70 | // Create liveTrack 71 | if ( m.getAddress() == "/live/name/track" ) { 72 | int order = m.getArgAsInt32( 0 ); 73 | string name = m.getArgAsString( 1 ); 74 | tracks.push_back( new liveTrack(this, order, name) ); 75 | } 76 | 77 | // Create liveClip 78 | if ( m.getAddress() == "/live/name/clip" ) { 79 | int track_order = m.getArgAsInt32( 0 ); 80 | int order = m.getArgAsInt32( 1 ); 81 | string name = m.getArgAsString( 2 ); 82 | clips.push_back( new liveClip(this, track_order, order, name) ); 83 | } 84 | 85 | // Create liveDevice 86 | if ( m.getAddress() == "/live/devicelist" ) { 87 | int track_order = m.getArgAsInt32( 0 ); 88 | int order = m.getArgAsInt32( 1 ); 89 | string name = m.getArgAsString( 2 ); 90 | devices.push_back( new liveDevice(this, track_order, order, name) ); 91 | } 92 | 93 | // Create liveParam 94 | if ( m.getAddress() == "/live/device/allparam" ) { 95 | int _track_o = m.getArgAsInt32( 0 ); 96 | int _device_o = m.getArgAsInt32( 1 ); 97 | for ( int i=0; i<10; i++ ) { 98 | int b = i * 3; 99 | int _parameter = m.getArgAsInt32( b + 2 ); 100 | float _val = m.getArgAsFloat( b + 3 ); 101 | string _name = m.getArgAsString( b + 4 ); 102 | params.push_back( new liveParam(this, _track_o, _device_o, _parameter, _val, _name) ); 103 | } 104 | } 105 | 106 | // Handle transport 107 | if ( m.getAddress() == "/bar_transport" ) { 108 | int _beat = m.getArgAsInt32( 0 ); 109 | if ( _beat >= 0 and playing == true ) { 110 | beat = _beat; 111 | step = 0; 112 | } 113 | } 114 | 115 | // Recieve tempo 116 | if ( m.getAddress() == "/live/tempo" ) { 117 | float _tempo = m.getArgAsFloat( 0 ); 118 | cout << "Tempo: " << _tempo << endl; 119 | tempo = tempo; 120 | } 121 | 122 | } 123 | } 124 | 125 | 126 | //-------------------------------------------------------- 127 | void liveSet::play(){ 128 | // Set playing flag, reset beat 129 | playing = true; 130 | // Send message to live 131 | ofxOscMessage m; 132 | m.setAddress( "/live/play" ); 133 | sender.sendMessage( m ); 134 | } 135 | 136 | 137 | //-------------------------------------------------------- 138 | void liveSet::stop(){ 139 | playing = false; 140 | beat = 0; 141 | step = 0; 142 | // Send message to live 143 | // ofxOscMessage m; 144 | // m.setAddress( "/live/stop" ); 145 | // sender.sendMessage( m ); 146 | // stop all tracks 147 | for ( int i=0; igetTrackOrder() ); 152 | m.addIntArg( s_clip->getOrder() ); 153 | sender.sendMessage( m ); 154 | } 155 | } 156 | 157 | 158 | //-------------------------------------------------------- 159 | void liveSet::getInfo(){ 160 | 161 | // Get tempo 162 | ofxOscMessage m; 163 | m.setAddress( "/live/tempo" ); 164 | sender.sendMessage( m ); 165 | 166 | } 167 | 168 | 169 | //-------------------------------------------------------- 170 | void liveSet::getTracks(){ 171 | ofxOscMessage m; 172 | m.setAddress( "/live/name/track" ); 173 | sender.sendMessage( m ); 174 | } 175 | 176 | 177 | //-------------------------------------------------------- 178 | void liveSet::getClips(){ 179 | ofxOscMessage m; 180 | m.setAddress( "/live/name/clip" ); 181 | sender.sendMessage( m ); 182 | } 183 | 184 | 185 | //-------------------------------------------------------- 186 | // Get devices for each track 187 | void liveSet::getDevices(){ 188 | 189 | for ( int i=0; i<2; i++ ) { 190 | 191 | cout << "PIONG" << endl; 192 | 193 | ofxOscMessage m; 194 | m.setAddress( "/live/devicelist" ); 195 | m.addIntArg( i ); 196 | sender.sendMessage( m ); 197 | 198 | } 199 | } 200 | 201 | 202 | //-------------------------------------------------------- 203 | liveClip* liveSet::getClipByName(string name, int track_order) { 204 | for ( int i=0; igetName() == name and clips[i]->getTrackOrder() == track_order) { 207 | return clips[i]; 208 | } 209 | } 210 | } 211 | 212 | 213 | //-------------------------------------------------------- 214 | liveParam* liveSet::getParamByName(string name, int track_order) { 215 | for ( int i=0; igetName() == name and params[i]->getTrackOrder() == track_order) { 218 | return params[i]; 219 | } 220 | } 221 | } 222 | 223 | 224 | //-------------------------------------------------------------- 225 | int liveSet::getBeat() { 226 | return beat; 227 | } 228 | 229 | 230 | //-------------------------------------------------------------- 231 | int liveSet::getStep() { 232 | return step; 233 | } 234 | 235 | 236 | //-------------------------------------------------------------- 237 | bool liveSet::getPlaying() { 238 | return playing; 239 | } 240 | 241 | 242 | //-------------------------------------------------------------- 243 | void liveSet::sendMessage(ofxOscMessage message) { 244 | sender.sendMessage( message ); 245 | } 246 | 247 | 248 | //-------------------------------------------------------------- 249 | void liveSet::setCrossfader(float val) { 250 | ofxOscMessage m; 251 | m.setAddress( "/live/master/crossfader" ); 252 | m.addFloatArg( (val * 2) - 1 ); 253 | sender.sendMessage( m ); 254 | } --------------------------------------------------------------------------------