AKAI_APCmini002.py 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. """
  4. This file is part of librelight.
  5. librelight is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 2 of the License, or
  8. (at your option) any later version.
  9. librelight is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with librelight. If not, see <http://www.gnu.org/licenses/>.
  15. (c) micha.rathfelder@gmail.com
  16. """
  17. #import init
  18. #init.init()
  19. import socket,time
  20. import sys
  21. sys.stdout.write("\x1b]2;APCmini\x07")
  22. import sys
  23. import os
  24. import lib.chat as chat
  25. import random
  26. if 0:#0: # if pygame midi ?
  27. # Midi modul von Python game zur Platformunabhängigkeit
  28. # z.b. Windows
  29. # 10 MB RAM
  30. from interfaces.midi.lib.pygamemidi_wraper import pygamemidi
  31. midi = pygamemidi(out=2,inp=3)
  32. else: # if linux
  33. # 4 MB RAM
  34. #from simplemidi_wraper import simplemidi
  35. from lib.simplemidi_wraper import simplemidi
  36. midi = simplemidi("/dev/snd/midiC1D0") #,inp="/dev/midi1")
  37. nr = 0
  38. while 1:
  39. device = midi.get_device_info(nr)
  40. if device == None:
  41. break
  42. else:
  43. print(nr , device)
  44. nr += 1
  45. cli = None
  46. import socket, struct
  47. c = chat.tcp_sender()
  48. def send(msg):
  49. c.send(msg)
  50. def main():
  51. global send
  52. global node
  53. global toggel,toggel1,toggel2,toggel3
  54. fader = 40
  55. values = []
  56. fader_value= [0]*9
  57. firstfader = 48
  58. fader_move_delay = 0
  59. tog = 0
  60. tog0 = 1
  61. tog1 = 1
  62. cmd = ""
  63. release = 1
  64. while True:
  65. if release:
  66. release = 0
  67. for i in range(4):
  68. midi.write([144,60+i,5])
  69. midi.write([144,52+i,5])
  70. midi.write([144,44+i,5])
  71. midi.write([144,36+i,5])
  72. midi.write([144,24+i,3])
  73. midi.write([144,24+i+4,3])
  74. midi.write([144,56+i,1])
  75. midi.write([144,8+i,1])
  76. midi.write([144,12+i,1])
  77. if midi.poll():
  78. midi_date = midi.read(1)
  79. print("in:",midi_date)
  80. if midi_date[0] == 176:
  81. if midi_date[1] == 55:
  82. fader = midi_date[2]/127.*8
  83. print("LED:",[144,7,fader])
  84. midi.write([144,7,fader])
  85. print("setfadert to", fader)
  86. if midi_date[1] >= firstfader and midi_date[1] <= firstfader+8:
  87. value = int(midi_date[2]*2.008)
  88. fader_id = midi_date[1] - firstfader
  89. fader_value[fader_id] = value
  90. print("FADER:",fader_id+1,value)
  91. if fader_id == 0:
  92. msg = "group 33 level "+str(int(value))
  93. send(msg)
  94. elif fader_id == 1:
  95. msg = "group 34 level "+str(int(value))
  96. send(msg)
  97. elif fader_id == 2:
  98. msg = "group 35 level "+str(int(value))
  99. send(msg)
  100. elif fader_id == 3:
  101. msg = "group 36 level "+str(int(value))
  102. send(msg)
  103. elif fader_id == 4:
  104. msg = "group 37 level "+str(int(value))
  105. send(msg)
  106. elif fader_id == 5:
  107. msg = "group 38 level "+str(int(value))
  108. send(msg)
  109. elif fader_id == 6:
  110. #value = value*-1+255 #invert
  111. value2 = int(value/255.*100)*2
  112. #msg = "stack 2 indelay="+str(value2)+" ;EOB"
  113. msg = "effect 1 SIZE "+str(value2)+" ;EOB"
  114. send(msg)
  115. elif fader_id == 7:
  116. #value = value*-1+255 #invert
  117. value2 = int(value/255.*100)*2
  118. #msg = "stack 2 indelay="+str(value2)+" ;EOB"
  119. msg = "effect 7 SIZE "+str(value2)+" ;EOB"
  120. send(msg)
  121. elif fader_id == 8:
  122. if value <= 127:
  123. value2 = value / 127.
  124. else:
  125. value2 = (value - 127) / 20. +1.
  126. #value2 = value / 30.5
  127. msg = "preset time "+str(value2)+" ;EOB"
  128. send(msg)
  129. #value2 = value / 25.5
  130. #msg = "preset time_pt "+str(value2)+" ;EOB"
  131. #send(msg)
  132. elif midi_date[0] == 144:
  133. if midi_date[1] == 56:
  134. send("clear")
  135. elif midi_date[1] == 57:
  136. send("store")
  137. elif midi_date[1] == 58:
  138. send("edit")
  139. elif midi_date[1] == 33:
  140. send("preview")
  141. elif midi_date[1] == 34:
  142. send("set")
  143. elif midi_date[1] == 35:
  144. send("next")
  145. elif midi_date[1] >= 8 and midi_date[1] <= 15 :
  146. nr = midi_date[1]-8+25
  147. send("xpreset "+str(int( nr )) )
  148. elif midi_date[1] >= 24 and midi_date[1] <= 31 :
  149. nr = midi_date[1]-24+33
  150. send("xpreset "+str(int( nr )) )
  151. elif midi_date[1] == 20:
  152. pass#send("stack 1 on")
  153. elif midi_date[1] == 12:
  154. pass#send("stack 1 go")
  155. elif midi_date[1] == 4:
  156. pass#send("stack 1 run")
  157. elif midi_date[1] == 68:
  158. pass#send("stack 1 stop")
  159. elif midi_date[1] == 0:
  160. pass#msg = "sel 1"
  161. pass#send(msg)
  162. elif midi_date[1] == 1:
  163. pass#msg = "sel 2"
  164. pass#send(msg)
  165. elif midi_date[1] == 2:
  166. pass#msg = "sel 3"
  167. pass#send(msg)
  168. elif midi_date[1] == 64:
  169. pass#msg = "group 1 sel 1 "
  170. pass#send(msg)
  171. elif midi_date[1] == 65:
  172. pass#msg = "group 25 sel 1 "
  173. pass#send(msg)
  174. elif midi_date[1] == 66:
  175. pass#msg = "group 17 sel 1 "
  176. pass#send(msg)
  177. elif midi_date[1] == 86:
  178. #msg = "group 25 sel 1 "
  179. #send(msg)
  180. #ipc = cli.ipc_write({"SDL-GUI":"VIEW:programmer"})
  181. pass
  182. elif midi_date[1] == 85:
  183. pass
  184. #msg = "group 25 sel 1 "
  185. #send(msg)
  186. #ipc = cli.ipc_write({"SDL-GUI":"VIEW:groups"})
  187. elif midi_date[1] == 21:
  188. pass
  189. #send("stack 2 on")
  190. elif midi_date[1] == 13:
  191. pass
  192. #send("stack 2 go")
  193. elif midi_date[1] == 5:
  194. pass
  195. #send("stack 2 run")
  196. elif midi_date[1] == 69:
  197. pass
  198. #send("stack 2 stop")
  199. elif midi_date[1] == 22:
  200. pass
  201. #send("stack 2 mode ;")
  202. elif midi_date[1] == 14:
  203. pass
  204. #send("stack 2 dir ;")
  205. elif midi_date[1] == 6:
  206. #send("stack 2 dyn=rider,,1 ;")
  207. send("effect 1 DIR 0")
  208. elif midi_date[1] == 7:
  209. pass
  210. send("effect 7 DIR 0")
  211. #send("stack 2 dyn=rnd,,1 ;")
  212. if midi_date[0] == 128:
  213. midi_date[2] = 0
  214. midi_date[0] = 144
  215. print("release")
  216. release = 1
  217. else:
  218. midi_date[2] = int(fader)
  219. #if midi_date[1] <= 71:
  220. # midi_date[1] = midi_date[1]+8
  221. if midi_date[0] != 176:
  222. print("write",midi_date)
  223. midi.write(midi_date)
  224. if midi_date[0] == 128:
  225. for i in range(4):
  226. midi.write([144,60+i,5])
  227. midi.write([144,52+i,5])
  228. midi.write([144,44+i,5])
  229. midi.write([144,36+i,5])
  230. time.sleep(0.0002)
  231. if (int(time.time())) % 2 == 0:
  232. if tog0:
  233. tog0 = 0
  234. tog1 = 1
  235. midi.write([144,82,0])
  236. #print("o")
  237. else:
  238. if tog1:
  239. tog0 = 1
  240. tog1 = 0
  241. midi.write([144,82,3])
  242. #print("oo")
  243. import _thread as thread
  244. main()
  245. node = 244
  246. node2 = 0
  247. while 1:
  248. inp = raw_input("end")
  249. try:
  250. inp = inp.split(" ")
  251. midi.write(inp)
  252. midi.write(inp)
  253. except:pass