apcmini.py 11 KB

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