def st_led_off(): leds[count % 2].off() print('LED off') def on(dev, msg, raw): if raw[2] == 0: return off(dev, msg, raw) global count count += 1 st_bz_on(raw[1]) devel.status(f'{count}個の発音信号をスタディーノに送ったよ!') st_led_on() print('受信: ', dev, msg, raw) def off(dev, msg, raw): st_bz_off() st_led_off() mid.callback(indev, '9', on) mid.callback(indev, '8', off) mid.listen(indev) devel.wait(title='studuino buzzer test', text='studuinoのブザーを鳴らすよ') studuino.stop() mid.stop_process()
def thru(dev, msg, raw): global count_success, count_failed if raw[0] & 0xF0 in {0x90, 0x80}: if raw[1] % 12 in {1, 3, 4, 6, 8, 10, 11}: mid.send(outdev, msg) if raw[0] & 0xF0 == 0x90 and raw[2] > 0: count_success += 1 devel.status( f'{count_success+count_failed}回中、ミスタッチ{count_failed}回') else: if raw[0] & 0xF0 == 0x90 and raw[2] > 0: count_failed += 1 prog = random.randint(0, 47) devel.status(f'間違えんなドアホっ!\nお仕置きじゃ!\n音色を{prog}番に変えたったぞ!') mid.send(outdev, b'C%X%02X' % (raw[0] & 0xF, prog)) else: mid.send(outdev, msg) print('受信: ', dev, msg) mid.callback(None, '******', thru) mid.listen(indev) devel.wait(title='signal masking', text='信号の取捨選択 Bメジャーのスケールノートだけ通すよ!\n' '間違えるたびにランダムに音色が変わるよ') mid.stop_process()
def op(dev, msg, raw): cmd = (raw[0]&0xF0)>>4 note = raw[1] vel = raw[2] if vel>0: vel = 127 # ベロシティ固定 cur_ch = raw[0]&0xF ch1 = (cur_ch + 1)%16 # 別のチャンネル ch2 = (cur_ch + 2)%16 # さらに別のチャンネル if not_initialized: init(cur_ch,ch1,ch2) mid.send(outdev, msg) mid.send(outdev, b'%d%X%02X%02X'%(cmd,ch1,note-24,vel)) mid.send(outdev, b'%d%X%02X%02X'%(cmd,ch2,note+12,vel)) print('受信: ', dev, msg) def thru(dev,msg,raw): mid.send(outdev, msg) print('受信(OTHER): ', dev, msg) mid.callback(None,'9,8', op) mid.callback(None,'otherwise', thru) mid.listen(indev); devel.wait(title='simple octaver', text='オクターバー!\n' '2オクターブ下をベースの音色で、\n' '1オクターブ上をピアノの音色で同時に鳴らすよ\n' 'ベロシティは最大音量に固定するよ') mid.stop_process()
def thru(dev, msg, raw): global note_count st = raw[0] if st & 0xF0 in {0x90, 0x80}: if st & 0xF0 == 0x90 and raw[2] > 0: note_count += 1 else: note_count -= 1 if note_count <= 1: mod_level = 0 elif note_count <= 4: mod_level = (note_count - 1) * 32 else: mod_level = 127 ch = raw[0] & 0xF mid.send(outdev, msg) mid.send(outdev, b'B%X%02X%02X' % (ch, 1, mod_level)) devel.status(f'同時発音数 {note_count}音、\n変調レベル = {mod_level}') else: mid.send(outdev, msg) print('受信: ', dev, msg) mid.callback(None, '******', thru) mid.listen(indev) devel.wait(title='automatic modulator', text='自動でモジュレーションを掛けるよ!\n' '単音では掛からないよ。\n和音の構成音数が増えるに連れて深く掛かるよ!') mid.stop_process()
song_note = get_song_note() mid.send(outdev,b'9%X%02X%02X'%(ch,song_note,vel)) led.on() elif raw[0]&0xF0 == 0x80 or (raw[0]&0xF0 == 0x90 and raw[2]==0): ch = raw[0]&0xF note = raw[1] if note == current_base_note or note%12 == current_base_note%12: mid.send(outdev,b'8%X%02X00'%(ch,current_note)) led.off() else: mid.send(outdev,msg) print('受信: ', dev, msg) mid.callback(None,'******', bach) #mid.send(outdev, 'C030') mid.listen(indev); studuino.start('COM3') time.sleep(2) led = studuino.LED() led.attach(studuino.A0) devel.wait(title="let's sing!", text='バッハの「主よ人の望みの喜びよ」を歌うよ!\n' '最初に叩いたキーのノートが調のトニックになるよ\n' 'オクターブ関係のキーを叩くと直前のノートを繰り返せるよ') mid.stop_process() studuino.stop()
import midiate import devel mid = midiate.Midiator() mid.start_process() indev = devel.open_input(mid); def get_note_name(midi_note): mod = midi_note % 12 return ('C','C#','D','D#','E','F','F#','G','G#','A','A#','B')[mod] def mon(dev, sig , raw): sig_type = '' chk = raw[0]&0xF0 if chk==0x90: sig_type = 'NOTE ON - ' + get_note_name(raw[1]) elif chk==0x80: sig_type = 'NOTE OFF - ' + get_note_name(raw[1]) elif chk==0xB0: sig_type = 'CONTROL CHANGE' elif chk==0xC0: sig_type = 'PROGRAM CHANGE' devel.status(f'{sig.decode()} {sig_type}') print('受信: ', dev, sig, raw) mid.callback(indev,'******',mon) mid.listen(indev); devel.wait(title='MIDI signal monitor', text='信号をモニタするよDEMO') mid.stop_process()
# -*- coding: utf-8 -*- import midiate import devel mid = midiate.Midiator() mid.start_process() indev, outdev = devel.open_both_io(mid) mid.send(outdev, 'C010') count = 0 def thru(dev, msg, raw): global count mid.send(outdev, msg) count += 1 devel.status(f'{count}個の信号を中継したよ!') print('受信: ', dev, msg, raw) mid.callback(indev, '9,8', thru) mid.listen(indev) devel.wait(title='signal thru', text='単純な信号の中継(ノート信号のみ)') mid.stop_process()
# -*- coding: utf-8 -*- import midiate import devel mid = midiate.Midiator() mid.start_process() indev, outdev = devel.open_both_io(mid) mid.send(outdev, 'C000') count = 0 def thru(dev, msg, raw): global count mid.send(outdev, msg) count += 1 devel.status(f'{count}個の信号を中継したよ!') print('受信: ', dev, msg, raw) mid.callback(None, '******', thru) mid.listen(indev) devel.wait(title='signal thru', text='単純な信号の中継') mid.stop_process()