micha 3 lat temu
rodzic
commit
182ce30fc1
6 zmienionych plików z 463 dodań i 3 usunięć
  1. 307 0
      AKAI_APCmini002.py
  2. 1 1
      console.py
  3. 0 0
      lib/chat.py
  4. 0 0
      lib/motion.py
  5. 150 0
      lib/simplemidi_wraper.py
  6. 5 2
      send_loop.py

+ 307 - 0
AKAI_APCmini002.py

@@ -0,0 +1,307 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+This file is part of librelight.
+
+librelight is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+librelight is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with librelight.  If not, see <http://www.gnu.org/licenses/>.
+
+(c) micha.rathfelder@gmail.com
+"""
+
+
+#import init
+#init.init()
+import socket,time
+
+import sys
+sys.stdout.write("\x1b]2;APCmini\x07")
+
+
+import sys
+import os
+
+import lib.chat as chat
+
+import random
+
+
+if 0:#0: # if pygame midi ?
+    # Midi modul von Python game zur Platformunabhängigkeit
+    # z.b. Windows
+
+    # 10 MB RAM
+    from interfaces.midi.lib.pygamemidi_wraper import pygamemidi
+    midi = pygamemidi(out=2,inp=3)
+else: # if linux
+    #  4 MB RAM
+    #from simplemidi_wraper import simplemidi
+    from lib.simplemidi_wraper import simplemidi
+    midi = simplemidi("/dev/snd/midiC1D0") #,inp="/dev/midi1")
+
+
+nr = 0
+while 1:
+    device = midi.get_device_info(nr)
+    if device == None:
+        break
+    else:
+        print(nr , device)
+    nr += 1
+
+
+
+cli = None
+
+import socket, struct
+
+
+
+
+def main():
+    global send
+    global node
+    global toggel,toggel1,toggel2,toggel3
+    fader = 40
+    values = []
+    fader_value= [0]*9
+    firstfader = 48
+    fader_move_delay = 0
+    tog = 0
+    tog0 = 1
+    tog1 = 1
+    cmd = ""
+    release = 1
+
+    while True:
+        if release:
+            release = 0
+            for i in range(4):
+                midi.write([144,60+i,5])
+                midi.write([144,52+i,5])
+                midi.write([144,44+i,5])
+                midi.write([144,36+i,5])
+
+                midi.write([144,24+i,3])
+                midi.write([144,24+i+4,3])
+
+
+                midi.write([144,56+i,1])
+
+                midi.write([144,8+i,1])
+                midi.write([144,12+i,1])
+
+
+        if midi.poll():
+            midi_date = midi.read(1)
+
+            print("in:",midi_date)
+            if midi_date[0] == 176:
+                if midi_date[1] == 55:
+                    fader = midi_date[2]/127.*8
+
+                    print("LED:",[144,7,fader])
+                    midi.write([144,7,fader])
+
+
+                    print("setfadert to", fader)
+                if midi_date[1] >= firstfader and midi_date[1] <= firstfader+8:
+                    value = int(midi_date[2]*2.008)
+                    fader_id = midi_date[1] - firstfader
+                    fader_value[fader_id] = value
+                    print("FADER:",fader_id+1,value)
+                    if fader_id == 0:
+                        msg = "group 33 level "+str(int(value))
+                        send(msg)
+                    elif fader_id == 1:
+                        msg = "group 34 level "+str(int(value))
+                        send(msg)
+                    elif fader_id == 2:
+                        msg = "group 35 level "+str(int(value))
+                        send(msg)
+                    elif fader_id == 3:
+                        msg = "group 36 level "+str(int(value))
+                        send(msg)
+                    elif fader_id == 4:
+                        msg = "group 37 level "+str(int(value))
+                        send(msg)
+                    elif fader_id == 5:
+                        msg = "group 38 level "+str(int(value))
+                        send(msg)
+
+                    elif fader_id == 6:
+                        #value = value*-1+255 #invert
+                        value2 = int(value/255.*100)*2
+                        #msg = "stack 2 indelay="+str(value2)+" ;EOB"
+                        msg = "effect 1 SIZE "+str(value2)+" ;EOB"
+                        send(msg)
+                    elif fader_id == 7:
+                        #value = value*-1+255 #invert
+                        value2 = int(value/255.*100)*2
+                        #msg = "stack 2 indelay="+str(value2)+" ;EOB"
+                        msg = "effect 7 SIZE "+str(value2)+" ;EOB"
+                        send(msg)
+                    elif fader_id == 8:
+                        if value <= 127:
+                            value2 = value  / 127.
+                        else:
+                            value2 = (value - 127) / 20.   +1.
+                        #value2 = value / 30.5
+                        msg = "preset time "+str(value2)+" ;EOB"
+                        send(msg)
+
+                        #value2 = value / 25.5
+                        #msg = "preset time_pt "+str(value2)+" ;EOB"
+                        #send(msg)
+
+            elif midi_date[0] == 144:
+
+                if midi_date[1] == 56:
+                    send("clear")
+                elif midi_date[1] == 57:
+                    send("store")
+                elif midi_date[1] == 58:
+                    send("edit")
+                elif midi_date[1] == 33:
+                    send("preview")
+                elif midi_date[1] == 34:
+                    send("set")
+                elif midi_date[1] == 35:
+                    send("next")
+                elif midi_date[1] >= 8 and midi_date[1] <= 15 :
+                    nr = midi_date[1]-8+25
+                    send("xpreset "+str(int( nr )) )
+                elif midi_date[1] >= 24 and midi_date[1] <= 31 :
+                    nr = midi_date[1]-24+33
+                    send("xpreset "+str(int( nr )) )
+
+                elif midi_date[1] == 20:
+                    pass#send("stack 1 on")
+                elif midi_date[1] == 12:
+                    pass#send("stack 1 go")
+                elif midi_date[1] == 4:
+                    pass#send("stack 1 run")
+                elif midi_date[1] == 68:
+                    pass#send("stack 1 stop")
+                elif midi_date[1] == 0:
+                    pass#msg = "sel 1"
+                    pass#send(msg)
+                elif midi_date[1] == 1:
+                    pass#msg = "sel 2"
+                    pass#send(msg)
+                elif midi_date[1] == 2:
+                    pass#msg = "sel 3"
+                    pass#send(msg)
+                elif midi_date[1] == 64:
+                    pass#msg = "group 1 sel 1 "
+                    pass#send(msg)
+                elif midi_date[1] == 65:
+                    pass#msg = "group 25 sel 1 "
+                    pass#send(msg)
+                elif midi_date[1] == 66:
+                    pass#msg = "group 17 sel 1 "
+                    pass#send(msg)
+                elif midi_date[1] == 86:
+                    #msg = "group 25 sel 1 "
+                    #send(msg)
+                    #ipc = cli.ipc_write({"SDL-GUI":"VIEW:programmer"})
+                    pass
+
+                elif midi_date[1] == 85:
+                    pass
+                    #msg = "group 25 sel 1 "
+                    #send(msg)
+                    #ipc = cli.ipc_write({"SDL-GUI":"VIEW:groups"})
+                elif midi_date[1] == 21:
+                    pass
+                    #send("stack 2 on")
+                elif midi_date[1] == 13:
+                    pass
+                    #send("stack 2 go")
+                elif midi_date[1] == 5:
+                    pass
+                    #send("stack 2 run")
+                elif midi_date[1] == 69:
+                    pass
+                    #send("stack 2 stop")
+
+                elif midi_date[1] == 22:
+                    pass
+                    #send("stack 2 mode ;")
+                elif midi_date[1] == 14:
+                    pass
+                    #send("stack 2 dir ;")
+                elif midi_date[1] == 6:
+                    #send("stack 2 dyn=rider,,1 ;")
+                    send("effect 1 DIR 0")
+                elif midi_date[1] == 7:
+                    pass
+                    send("effect 7 DIR 0")
+                    #send("stack 2 dyn=rnd,,1 ;")
+
+            if midi_date[0] == 128:
+                midi_date[2] = 0
+                midi_date[0] = 144
+                print("release")
+                release = 1
+
+
+
+            else:
+                midi_date[2]  = int(fader)
+            #if midi_date[1] <= 71:
+            #    midi_date[1]  = midi_date[1]+8
+
+
+
+            if midi_date[0] != 176:
+                print("write",midi_date)
+                midi.write(midi_date)
+
+
+            if midi_date[0] == 128:
+                for i in range(4):
+                    midi.write([144,60+i,5])
+                    midi.write([144,52+i,5])
+                    midi.write([144,44+i,5])
+                    midi.write([144,36+i,5])
+        time.sleep(0.0002)
+
+        if (int(time.time())) % 2 == 0:
+            if tog0:
+                tog0 = 0
+                tog1 = 1
+                midi.write([144,82,0])
+                #print("o")
+        else:
+            if tog1:
+                tog0 = 1
+                tog1 = 0
+                midi.write([144,82,3])
+                #print("oo")
+
+import _thread as thread
+main()
+
+node = 244
+
+node2 = 0
+while 1:
+    inp = raw_input("end")
+    try:
+        inp = inp.split(" ")
+        midi.write(inp)
+        midi.write(inp)
+    
+    except:pass

+ 1 - 1
console.py

@@ -25,7 +25,7 @@ import socket
 import struct
 import random
  
-import chat
+import lib.chat as chat
 import ArtNetNode as ANN
 import _thread as thread  
 #thread.start_new_thread

+ 0 - 0
chat.py → lib/chat.py


+ 0 - 0
motion.py → lib/motion.py


+ 150 - 0
lib/simplemidi_wraper.py

@@ -0,0 +1,150 @@
+#! /usr/bin/python
+# -*- coding: utf-8 -*-
+
+"""
+This file is part of LibreLight.
+
+LibreLight is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+LibreLight is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with LibreLight.  If not, see <http://www.gnu.org/licenses/>.
+
+(c) 2012 micha.rathfelder@gmail.com
+"""
+
+# file descriptor on linux /dev/midi1
+import sys
+import os
+#import fcntl
+import _thread as thread
+import time
+import copy
+
+class simplemidi(object):
+    def __init__(self,device="/dev/midi1"):
+        self.__lock = thread.allocate_lock()
+        self.__mode = ""
+        #self.__lock.acquire() 
+        #self.__lock.release()
+        self.__data = ""
+        self.__name = device
+        self.__open()
+    def __close(self):    
+        os.close( self.__midi )
+    def __open(self):
+        try:
+            option = os.O_RDWR | os.O_NONBLOCK # os.O_RDONLY | os.O_NONBLOCK
+            self.__midi = os.open( self.__name, option)
+                
+            self.__mode = "a"
+            
+        except OSError as e:
+            print("File", self.__name, "ERR: {0} ".format(e.args) )
+
+            try:
+                self.__mode = "rw"
+                option = os.O_RDONLY | os.O_NONBLOCK
+                self.__midi = os.open( self.__name, option)
+                print("DEVICE MODE:",self.__mode)
+            except OSError as e:
+                print("File", self.__name, "ERR: {0} ".format(e.args) )
+                input()
+                sys.exit()
+                
+        print("DEVICE MODE:",self.__mode)
+    def init(self):
+        #placeholder pygame
+        pass
+    def get_device_info(self,nr):
+        if nr == 1:
+            return "simplemidi", self.__device
+        else:
+            return None
+    def write_delayed(self,data):
+        #import thread        
+        thread.start_new_thread(self._write_delayed,([data,0.01],)) #midi writeloop
+        thread.start_new_thread(self._write_delayed,([data,0.1],)) #midi writeloop
+        thread.start_new_thread(self._write_delayed,([data,1],)) #midi writeloop
+    def _write_delayed(self,data):
+        time.sleep(data[1])
+        self.write(data[0])
+                    
+    def write(self,data):
+        self.__lock.acquire() 
+        # change midi file to write mode
+        if self.__mode == "rw":
+            os.close(self.__midi)
+            option = os.O_WRONLY | os.O_NONBLOCK
+            self.__midi = os.open( self.__name, option)
+
+        if len(data) == 3:
+            msg = ""
+            
+            try:
+                msg = chr(int(data[0])) + chr(int(data[1])) + chr(int(data[2]) ) 
+                #if data[0] != 191:
+                #    print(data#[msg])
+                os.write(self.__midi, bytes(msg,"utf-8")  )
+            except Exception as e:# SyntaxError:print("midi err",[msg,data ])
+                print("midi-single-write:", e, data)
+                #self.__close() #STOPPING MIDI ...
+                #self.__open()
+        elif len(data) > 3:
+            #print("multi sending---------------------------")
+            for i in data:
+                if len(i) == 3:
+                    msg = ""
+                    
+                    try:
+                        msg = chr(int(i[0])) + chr(int(i[1])) + chr(int(i[2])) 
+                        print([msg])
+                        os.write(self.__midi, msg  )
+                    except Exception as e:
+                        pass
+                        print("midi-multi-write:", e, data)
+                
+        
+        # change midi file to read mode
+        if self.__mode == "rw":
+            os.close(self.__midi)
+            option = os.O_RDONLY | os.O_NONBLOCK
+            self.__midi = os.open( self.__name, option)
+        self.__lock.release()
+        
+    def read(self,count=3):
+        self.__lock.acquire()
+        data = copy.deepcopy(self.__data)
+         
+        self.__lock.release()
+        return data
+        
+    def poll(self,sysex=0):
+        self.__lock.acquire() 
+        try: 
+            if sysex:
+                self.__data = os.read(self.__midi, 1) #read abort if no data to read
+            else:
+                inp = os.read(self.__midi, 3) #read abort if no data to read
+                try:
+                    #self.__data =  [ ord( inp[0] ) ,ord( inp[1] ), ord( inp[2] ) ]
+                    self.__data =  [ inp[0]  , inp[1] ,  inp[2] ]
+                except KeyError as e:
+                    print("File", self.__name, "ERR: {0} ".format(e.args) ,[inp])
+                except IndexError as e:
+                    print("File", self.__name, "ERR: {0} ".format(e.args) ,[inp])
+                        
+            self.__lock.release()
+            return 1
+        except OSError: 
+            time.sleep(0.01) # CPU STRESSLESS
+            self.__lock.release()
+            return 0
+

+ 5 - 2
send_loop.py

@@ -1,7 +1,10 @@
-import chat
+
+
+
+import lib.chat as chat
 import time
 
-import motion 
+import lib.motion as motion 
 
 def inp():
     c = chat.tcp_sender()