連日、このネタ。
前に進まない。
初心者プログラミングにつき注意!
Gertduinoでサイレントギターシンセサイザーの準備。
とりあえず、ArduinoとRaspberryPiの合体が出来たので、MIDIのテストをしていた。
経緯は以下の通り。
①Ardumidi.hのコンパイル時エラーの修正
②Pythonでシリアルデータ読み取り
③Gertduino+RaspberryPiでMIDI
プログラムを「Ctrl+c」で強制終了すると、それがnote_onの時だと、音が閉じないまま、残響が残る(前回の動画はその不具合を抱えたままだった)。
今回は、「Quit」ボタンを作ろうと思っていたが、時間切れで出来なかった。
今回、付け加えたボタンは、「Pressure」と「Reset」だ。
MIDI信号をいろいろいじくってと思っていた。
出来れば全数、確認できればと思っていたが、プレッシャーを変えただけでも、変化は聞き分けられず、それは、やめようかと思う。
ギターの周辺機材で変化が付けばいいという指摘があったけど、そうすることにした。
3ヶ月経って、この状況だから、あんまり時間をかけてはいられないと思う。
次のステップに行って、出来が悪くても、とりあえず出来上がりましたっていうところに持っていきたい。
#!/usr/bin/env python #coding: utf8 from Tkinter import * import pygame import pygame.midi from time import sleep import serial import threading import time inst = 0 note = 0 Program_change = 0 Pressure = 0 velocity = 0 def program(): global Program_change Program_change = Program_change + 1 def pressure(): global Pressure Pressure = Pressure + 30 def reset(): global Program_change,Pressure Program_change = 0 Pressure = 0 class midi_test(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.setDaemon(True) self.i = 0 def midi_load(): pygame.init() pygame.midi.init() port = 2 ser = serial.Serial('/dev/ttyAMA0', baudrate=38400) global midiOutput global out midiOutput = pygame.midi.Output(port, 0) midiOutput.set_instrument(inst) TIME = 0 while TIME in range(25): TIME = TIME + 1 message = [0, 0, 0] i = 0 while i < 3: data = ord(ser.read(1)) if data >> 7 != 0: i = 0 message[i] = data i += 1 if i == 2 and message[0] >> 4 == 12: message[2] = 0 i = 3 messagetype = message[0] >> 4 messagechannel = (message[0] & 15) + 1 note = message[1] if len(message) > 1 else None velocity = message[2] if len(message) > 2 else None midiOutput.write_short(0xc0,Program_change) midiOutput.write_short(0xa0,Pressure) if messagetype == 9: # Note on midiOutput.note_on(note, velocity) # sleep(.25) elif messagetype == 8: # Note off midiOutput.note_off(note, velocity) elif messagetype == 12: # Program change pass # sleep(.25) # midiOutput.write_short(0xb0,123) del midiOutput pygame.midi.quit() root = Tk() button1=Button(root,text='START',bd='4',bg='dimgray',fg='white',command=midi_load) button1.grid(column=1,row=0) button2=Button(root,text='PROGRAM',bd='4',bg='dimgray',fg='white',command=program) button2.grid(column=2,row=0) button3=Button(root,text='PRESSURE',bd='4',bg='dimgray',fg='white',command=pressure) button3.grid(column=3,row=0) button4=Button(root,text='RESET',bd='4',bg='brown4',fg='white',command=reset) button4.grid(column=4,row=0) root.mainloop() if __name__ == "__main__": t = midi_test() t.start() #time.sleep(30)
