apcmini.py 11 KB

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