AKAI_APCmini002.py 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. def main():
  48. global send
  49. global node
  50. global toggel,toggel1,toggel2,toggel3
  51. fader = 40
  52. values = []
  53. fader_value= [0]*9
  54. firstfader = 48
  55. fader_move_delay = 0
  56. tog = 0
  57. tog0 = 1
  58. tog1 = 1
  59. cmd = ""
  60. release = 1
  61. while True:
  62. if release:
  63. release = 0
  64. for i in range(4):
  65. midi.write([144,60+i,5])
  66. midi.write([144,52+i,5])
  67. midi.write([144,44+i,5])
  68. midi.write([144,36+i,5])
  69. midi.write([144,24+i,3])
  70. midi.write([144,24+i+4,3])
  71. midi.write([144,56+i,1])
  72. midi.write([144,8+i,1])
  73. midi.write([144,12+i,1])
  74. if midi.poll():
  75. midi_date = midi.read(1)
  76. print("in:",midi_date)
  77. if midi_date[0] == 176:
  78. if midi_date[1] == 55:
  79. fader = midi_date[2]/127.*8
  80. print("LED:",[144,7,fader])
  81. midi.write([144,7,fader])
  82. print("setfadert to", fader)
  83. if midi_date[1] >= firstfader and midi_date[1] <= firstfader+8:
  84. value = int(midi_date[2]*2.008)
  85. fader_id = midi_date[1] - firstfader
  86. fader_value[fader_id] = value
  87. print("FADER:",fader_id+1,value)
  88. if fader_id == 0:
  89. msg = "group 33 level "+str(int(value))
  90. send(msg)
  91. elif fader_id == 1:
  92. msg = "group 34 level "+str(int(value))
  93. send(msg)
  94. elif fader_id == 2:
  95. msg = "group 35 level "+str(int(value))
  96. send(msg)
  97. elif fader_id == 3:
  98. msg = "group 36 level "+str(int(value))
  99. send(msg)
  100. elif fader_id == 4:
  101. msg = "group 37 level "+str(int(value))
  102. send(msg)
  103. elif fader_id == 5:
  104. msg = "group 38 level "+str(int(value))
  105. send(msg)
  106. elif fader_id == 6:
  107. #value = value*-1+255 #invert
  108. value2 = int(value/255.*100)*2
  109. #msg = "stack 2 indelay="+str(value2)+" ;EOB"
  110. msg = "effect 1 SIZE "+str(value2)+" ;EOB"
  111. send(msg)
  112. elif fader_id == 7:
  113. #value = value*-1+255 #invert
  114. value2 = int(value/255.*100)*2
  115. #msg = "stack 2 indelay="+str(value2)+" ;EOB"
  116. msg = "effect 7 SIZE "+str(value2)+" ;EOB"
  117. send(msg)
  118. elif fader_id == 8:
  119. if value <= 127:
  120. value2 = value / 127.
  121. else:
  122. value2 = (value - 127) / 20. +1.
  123. #value2 = value / 30.5
  124. msg = "preset time "+str(value2)+" ;EOB"
  125. send(msg)
  126. #value2 = value / 25.5
  127. #msg = "preset time_pt "+str(value2)+" ;EOB"
  128. #send(msg)
  129. elif midi_date[0] == 144:
  130. if midi_date[1] == 56:
  131. send("clear")
  132. elif midi_date[1] == 57:
  133. send("store")
  134. elif midi_date[1] == 58:
  135. send("edit")
  136. elif midi_date[1] == 33:
  137. send("preview")
  138. elif midi_date[1] == 34:
  139. send("set")
  140. elif midi_date[1] == 35:
  141. send("next")
  142. elif midi_date[1] >= 8 and midi_date[1] <= 15 :
  143. nr = midi_date[1]-8+25
  144. send("xpreset "+str(int( nr )) )
  145. elif midi_date[1] >= 24 and midi_date[1] <= 31 :
  146. nr = midi_date[1]-24+33
  147. send("xpreset "+str(int( nr )) )
  148. elif midi_date[1] == 20:
  149. pass#send("stack 1 on")
  150. elif midi_date[1] == 12:
  151. pass#send("stack 1 go")
  152. elif midi_date[1] == 4:
  153. pass#send("stack 1 run")
  154. elif midi_date[1] == 68:
  155. pass#send("stack 1 stop")
  156. elif midi_date[1] == 0:
  157. pass#msg = "sel 1"
  158. pass#send(msg)
  159. elif midi_date[1] == 1:
  160. pass#msg = "sel 2"
  161. pass#send(msg)
  162. elif midi_date[1] == 2:
  163. pass#msg = "sel 3"
  164. pass#send(msg)
  165. elif midi_date[1] == 64:
  166. pass#msg = "group 1 sel 1 "
  167. pass#send(msg)
  168. elif midi_date[1] == 65:
  169. pass#msg = "group 25 sel 1 "
  170. pass#send(msg)
  171. elif midi_date[1] == 66:
  172. pass#msg = "group 17 sel 1 "
  173. pass#send(msg)
  174. elif midi_date[1] == 86:
  175. #msg = "group 25 sel 1 "
  176. #send(msg)
  177. #ipc = cli.ipc_write({"SDL-GUI":"VIEW:programmer"})
  178. pass
  179. elif midi_date[1] == 85:
  180. pass
  181. #msg = "group 25 sel 1 "
  182. #send(msg)
  183. #ipc = cli.ipc_write({"SDL-GUI":"VIEW:groups"})
  184. elif midi_date[1] == 21:
  185. pass
  186. #send("stack 2 on")
  187. elif midi_date[1] == 13:
  188. pass
  189. #send("stack 2 go")
  190. elif midi_date[1] == 5:
  191. pass
  192. #send("stack 2 run")
  193. elif midi_date[1] == 69:
  194. pass
  195. #send("stack 2 stop")
  196. elif midi_date[1] == 22:
  197. pass
  198. #send("stack 2 mode ;")
  199. elif midi_date[1] == 14:
  200. pass
  201. #send("stack 2 dir ;")
  202. elif midi_date[1] == 6:
  203. #send("stack 2 dyn=rider,,1 ;")
  204. send("effect 1 DIR 0")
  205. elif midi_date[1] == 7:
  206. pass
  207. send("effect 7 DIR 0")
  208. #send("stack 2 dyn=rnd,,1 ;")
  209. if midi_date[0] == 128:
  210. midi_date[2] = 0
  211. midi_date[0] = 144
  212. print("release")
  213. release = 1
  214. else:
  215. midi_date[2] = int(fader)
  216. #if midi_date[1] <= 71:
  217. # midi_date[1] = midi_date[1]+8
  218. if midi_date[0] != 176:
  219. print("write",midi_date)
  220. midi.write(midi_date)
  221. if midi_date[0] == 128:
  222. for i in range(4):
  223. midi.write([144,60+i,5])
  224. midi.write([144,52+i,5])
  225. midi.write([144,44+i,5])
  226. midi.write([144,36+i,5])
  227. time.sleep(0.0002)
  228. if (int(time.time())) % 2 == 0:
  229. if tog0:
  230. tog0 = 0
  231. tog1 = 1
  232. midi.write([144,82,0])
  233. #print("o")
  234. else:
  235. if tog1:
  236. tog0 = 1
  237. tog1 = 0
  238. midi.write([144,82,3])
  239. #print("oo")
  240. import _thread as thread
  241. main()
  242. node = 244
  243. node2 = 0
  244. while 1:
  245. inp = raw_input("end")
  246. try:
  247. inp = inp.split(" ")
  248. midi.write(inp)
  249. midi.write(inp)
  250. except:pass