コード例 #1
0
from adafruit_midi.note_off import NoteOff
from adafruit_midi.note_on import NoteOn
from adafruit_midi.pitch_bend import PitchBend

midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)

print("Midi test")

# Convert channel numbers at the presentation layer to the ones musicians use
print("Default output channel:", midi.out_channel + 1)
print("Listening on input channel:",
      midi.in_channel + 1 if midi.in_channel is not None else None)

while True:
    # method per message interface
    midi.note_on(44, 120)
    time.sleep(0.25)
    midi.pitch_bend(random.randint(0, 16383))
    time.sleep(0.25)
    midi.note_off(44, 120)
    midi.control_change(3, 44)
    time.sleep(0.5)

    # send message(s) interface
    midi.send(NoteOn(44, 120))
    time.sleep(0.25)
    midi.send(PitchBend(random.randint(0, 16383)))
    time.sleep(0.25)
    midi.send([NoteOff("G#2", 120), ControlChange(3, 44)])
    time.sleep(0.5)
コード例 #2
0
# simple_test
import time
import random
import usb_midi
import adafruit_midi
from adafruit_midi.control_change import ControlChange
from adafruit_midi.note_off import NoteOff
from adafruit_midi.note_on import NoteOn
from adafruit_midi.pitch_bend import PitchBend

midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=0)

print("Midi test")

# Convert channel numbers at the presentation layer to the ones musicians use
print("Default output channel:", midi.out_channel + 1)
print("Listening on input channel:",
      midi.in_channel + 1 if midi.in_channel is not None else None)

while True:
    midi.send(NoteOn(44, 120))  # G sharp 2nd octave
    time.sleep(0.25)
    a_pitch_bend = PitchBend(random.randint(0, 16383))
    midi.send(a_pitch_bend)
    time.sleep(0.25)
    # note how a list of messages can be used
    midi.send([NoteOff("G#2", 120), ControlChange(3, 44)])
    time.sleep(0.5)
コード例 #3
0
    if abs(mod_val1 - mod_val2) > 2:
        #  update mod_val2
        mod_val2 = mod_val1
        #  create integer
        modulation = int(mod_val2)
        #  create CC message
        modWheel = ControlChange(1, modulation)
        #  send CC message
        midi.send(modWheel)

    #  pitchbend down value is updated...
    if abs(pitchDown_val1 - pitchDown_val2) > 75:
        #  update pitchDown_val2
        pitchDown_val2 = pitchDown_val1
        #  create PitchBend message
        pitchDown = PitchBend(int(pitchDown_val2))
        #  send PitchBend message
        midi.send(pitchDown)

    #  pitchbend up value is updated...
    if abs(pitchUp_val1 - pitchUp_val2) > 75:
        #  updated pitchUp_val2
        pitchUp_val2 = pitchUp_val1
        #  create PitchBend message
        pitchUp = PitchBend(int(pitchUp_val2))
        #  send PitchBend message
        midi.send(pitchUp)

    #  sustain value is updated...
    if abs(sus_val1 - sus_val2) > 2:
        #  update sus_val2
コード例 #4
0
        # scale from 0 to 127 (maximum cc 7bit value)
        new_mod_wheel = abs(scale_acc(ay, acc_nullzone, acc_range, 127))
        if (abs(new_mod_wheel - mod_wheel) > min_mod_change
                or (new_mod_wheel == 0 and mod_wheel != 0)):
            midi.send(ControlChange(midi_cc_modwheel, new_mod_wheel))
            mod_wheel = new_mod_wheel

        # scale from 0 to +/- 8191 (almost maximum signed 14bit values)
        new_pitch_bend_value = (
            pb_midpoint -
            scale_acc(ax, acc_nullzone, acc_range, pb_midpoint - 1))
        if (abs(new_pitch_bend_value - pitch_bend_value) > min_pb_change
                or (new_pitch_bend_value == pb_midpoint
                    and pitch_bend_value != pb_midpoint)):
            midi.send(PitchBend(new_pitch_bend_value))
            pitch_bend_value = new_pitch_bend_value

    # left button increase octave / semitones shift based on switch
    # does not currently clear playing notes (buglet)
    if button_left.value:
        if switch_left.value:
            octave += 1
            if octave > max_octave:
                octave = min_octave
            flashLED(pixels, octave)
        else:
            semitone += 1
            if semitone > max_semitone:
                semitone = min_semitone
            # semitone range is more than number of pixels!
コード例 #5
0
mode = True

while True:

    if touch1.value:  # CC mode
        pixels[0] = 0xBB0000
        pixels[1] = 0x0
        mode = False

    if touch2.value:  # pitch bend mode
        pixels[0] = 0x0
        pixels[1] = 0x0000FF
        mode = True

    if mode:
        prox_cc = int(map_range(apds.proximity, 0, 255, 0, 127))
        if last_prox_cc is not prox_cc:
            midi.send(ControlChange(CC_NUM, prox_cc))
            print("CC is", prox_cc)
            last_prox_cc = prox_cc
    else:
        prox_pitch = int(map_range(apds.proximity, 0, 255, 8192, 16383))
        if last_prox_pitch is not prox_pitch:
            midi.send(PitchBend(prox_pitch))
            print("Pitch bend is", prox_pitch)
            last_prox_pitch = prox_pitch

    prox_bright = map_range(apds.proximity, 0, 255, 0.01, 1.0)
    pixels.brightness = prox_bright
コード例 #6
0
        #  this converts the pot data into an int
        #  velocity data is sent with NoteOn message
        #  NoteOn is sent in the loop
        velocity = int(velocity_val2)
        #  delay to settle MIDI data
        time.sleep(0.001)

    #  reads analog input to send MIDI data for PitchBend
    #  compares previous picthbend pot value to current value
    if abs(pitchbend_val1 - pitchbend_val2) > 75:
        #  updates previous value to hold current value
        pitchbend_val2 = pitchbend_val1
        #  MIDI data has to be sent as an integer
        #  this converts the pot data into an int
        #  int is stored as a PitchBend message
        a_pitch_bend = PitchBend(int(pitchbend_val2))
        #  PitchBend message is sent
        midi.send(a_pitch_bend)
        #  delay to settle MIDI data
        time.sleep(0.001)

    #  checks position of the rotary switch
    #  determines which notes are mapped to the cherry mx switches
    for s in octave_selector:
        if not s.value:
            o = octave_selector.index(s)
            octave = octave_select[o]

        #  checks if strum select switch is engaged
        if not strum_select.value:
            #  if it is, then:
コード例 #7
0
while True:
    for i in range(len(touchs)):
        touch = touchs[i]
        touch.update()
        if touch.rose:
            led.value = True
            if i == chan_up_index:
                print('chan up!')
                midi_channel = min(midi_channel + 1, 15)
            elif i == chan_down_index:
                print('chan down!')
                midi_channel = max(midi_channel - 1, 0)
            elif i == pitch_up_index:
                print('pitch up!')
                pitchbend_val = 8192 + 4096
                midi.send(PitchBend(pitchbend_val), channel=midi_channel)
            elif i == pitch_down_index:
                print('pitch down!')
                pitchbend_val = 8192 - 4096
                midi.send(PitchBend(pitchbend_val), channel=midi_channel)
            elif i == mod_up_index:
                print('mod up!')
                modwheel_val = 127
                midi.send(ControlChange(midi_cc_num, modwheel_val),
                          channel=midi_channel)
            elif i == mod_down_index:
                print('mod down!')
                modwheel_val = 0
                midi.send(ControlChange(midi_cc_num, modwheel_val),
                          channel=midi_channel)
            else: