Changeset 12 for trunk/TouchOSC
- Timestamp:
- 03/07/09 15:23:23 (14 months ago)
- Location:
- trunk/TouchOSC
- Files:
-
- 1 added
- 1 edited
-
TouchOSC.py (modified) (5 diffs)
-
touchosc_config.txt (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/TouchOSC/TouchOSC.py
r11 r12 8 8 import OSC 9 9 import re 10 import os 10 11 from Logger import Logger 11 12 … … 23 24 self.log("Logging Enabled") 24 25 25 ip = RemixNet.get_ip() 26 self.log("Ableton IP: " + str(ip)) 27 28 self.oscServer = RemixNet.OSCServer(ip, 5001, None, 5000) 29 self.callbackManager = self.oscServer.callbackManager 30 self.oscServer.sendOSC('/touchosc/startup', 1) 31 32 self.c_instance.show_message("TouchOSC > Server Started on " + str(ip)) 26 local = RemixNet.get_ip() 27 self.log("Ableton IP: " + str(local)) 33 28 34 29 # Init all listeners 35 30 self.cc = [] 36 config = open('config.txt', 'r') 31 self.cache = [] 32 33 config = open(os.path.expanduser('~') + '/touchosc_config.txt', 'r') 37 34 35 first = 0 38 36 for line in config: 39 (page, item) = line.rsplit("/") 40 #item = re.sub("/\d^/", "", item) 37 line = line.rstrip() 41 38 42 if item == "rotary" or item == "toggle" or item == "fader" or item == "push": 43 pass 44 else if item == "xy": 45 pass 46 else if item == "multitoggle": 47 pass 48 else if item == "multifader": 49 pass 39 # First line is remote ip address 40 if first == 0: 41 remote = line 42 self.oscServer = RemixNet.OSCServer(remote, 5001, local, 5000) 43 self.callbackManager = self.oscServer.callbackManager 44 self.oscServer.sendOSC('/touchosc/startup', 1) 45 46 first = 1 47 else: 48 if re.search("xy", line): 49 self.cc.append(line) 50 self.cc.append(line) 51 self.cache.append(0) 52 self.cache.append(0) 53 else: 54 self.cc.append(line) 55 self.cache.append(0) 56 57 self.callbackManager.add(self.callback, line) 50 58 51 59 config.close() 52 53 60 54 for page in range(4): 55 for item in ("fader", "toggle", "xy", "push", "rotary"): 56 for no in range(6): 57 string = "/" + str(page) + "/" + str(item) + str(no) 58 self.cc.append(string) 59 self.callbackManager.add(self.callback, string) 61 self.c_instance.show_message("TouchOSC > Server Started on " + str(local) + ", sending data to: " + str(remote)) 62 63 self.song().add_current_song_time_listener(self.oscServer.processIncomingUDP) 60 64 61 65 ###################################################################### … … 75 79 76 80 def build_midi_map(self, midi_map_handle): 77 return 81 for i in range(0,20): 82 Live.MidiMap.forward_midi_cc(self.handle(), midi_map_handle, 0, i) 78 83 79 84 def send_midi(self, midi_bytes): 80 85 self.c_instance.send_midi(midi_bytes) 81 86 82 def receive_midi(self, midi_bytes): 83 return 87 def receive_midi(self, bytes): 88 cc = self.cc[bytes[1]] 89 val = float(bytes[2])/float(127) 90 91 if re.search("xy", cc): 92 self.cache[bytes[1]] = bytes[2] 93 xy1 = self.tuple_idx(self.cc, cc) 94 95 if bytes[1] == xy1: 96 val2 = float(self.cache[bytes[1] + 1])/float(127) 97 self.oscServer.sendOSC(str(self.cc[bytes[1]]), (val, val2)) 98 else: 99 val2 = float(self.cache[bytes[1] - 1])/float(127) 100 self.oscServer.sendOSC(str(self.cc[bytes[1]]), (val2, val)) 101 102 self.log("cc: " + str(bytes[1]) + " val: " + str(val) + " cc2: " + str((bytes[1] - 1)) + " val2: " + str(val2) + " control: " + str(self.cc[bytes[1]])) 103 104 else: 105 self.log("cc: " + str(bytes[1]) + " val: " + str(bytes[2]) + " control: " + str(self.cc[bytes[1]])) 106 self.oscServer.sendOSC(str(self.cc[bytes[1]]), val) 84 107 85 108 def can_lock_to_devices(self): … … 91 114 def suggest_output_port(self): 92 115 return '' 116 117 def suggest_map_mode(self, cc_no, channel): 118 return Live.MidiMap.MapMode.absolute 93 119 94 120 def __handle_display_switch_ids(self, switch_id, value): … … 127 153 # Main Touch OSC Functions 128 154 def callback(self, msg): 129 (page, item) = msg[0].rsplit("/") 130 item = re.sub("/\d^/", "", item) 155 if re.search("xy", msg[0]): 156 cc = self.tuple_idx(self.cc, msg[0]) 157 158 val = int(msg[2] * 127) 159 val2 = int(msg[3] * 127) 160 161 if abs(self.cache[cc] - val) > 0: 162 self.c_instance.send_midi((0xb0, cc, val)) 163 self.cache[cc] = val 164 165 self.log(str(msg[0]) + " cc: " + str(cc) + " val: " + str(val)) 166 167 if abs(self.cache[cc+1] - val2) > 0: 168 self.c_instance.send_midi((0xb0, cc + 1, val2)) 169 self.log(str(msg[0]) + " cc2: " + str(cc+1) + " val2: " + str(val2)) 170 171 self.cache[cc+1] = val2 172 173 else: 174 cc = self.tuple_idx(self.cc, msg[0]) 175 val = int(msg[2] * 127) 131 176 132 if item == "rotary" or item == "toggle" or item == "fader" or item == "push" or item == "multitoggle" or item == "multifader": 133 pass 134 135 else if item == "xy": 136 pass 137 138 cc = self.tuple_idx(self.cc, msg[0]) 139 val = int(msg[2] * 127) 140 141 self.log(str(msg[0]) + " cc: " + str(cc) + " val: " + str(val)) 142 self.c_instance.send_midi((0xb0, cc, val)) 177 self.c_instance.send_midi((0xb0, cc, val)) 143 178 179 self.log(str(msg[0]) + " cc: " + str(cc) + " val: " + str(val)) 180
Note: See TracChangeset
for help on using the changeset viewer.
