Esempio n. 1
0
 def playnote(self, note_idx, step_idx):
     r = random.randint(0, 99)
     if r >= self.prob[step_idx]:
         self.publish(("printat", None,
                       (step_idx * self.print_note_width + 2, 4, ".")))
         time.sleep(self.duration / 1000)
         self.publish(("printat", None,
                       (step_idx * self.print_note_width + 2, 4, " ")))
     else:
         duration_on = (self.durations[step_idx] * self.duration / 127)
         duration_off = self.duration - duration_on
         duration_on = duration_on / self.ratchets[step_idx]
         duration_off = duration_off / self.ratchets[step_idx]
         chosen = self.getnote(self.interval_indexes[note_idx])
         vel = self.vel[step_idx]
         note = (self.outchannel, chosen, vel)
         noteon = alsamidi.noteonevent(*note)
         noteoff = alsamidi.noteoffevent(*note)
         self.publish(("printat", None,
                       (step_idx * self.print_note_width + 2, 4, "*")))
         self.publish(("printat", None,
                       (note_idx * self.print_note_width + 2, 3, "*")))
         for i in range(self.ratchets[step_idx]):
             alsaseq.output(noteon)
             time.sleep(duration_on / 1000)
             alsaseq.output(noteoff)
             time.sleep(duration_off / 1000)
         self.publish(("printat", None,
                       (step_idx * self.print_note_width + 2, 4, " ")))
         self.publish(("printat", None,
                       (note_idx * self.print_note_width + 2, 3, " ")))
Esempio n. 2
0
    def test(self):
        from alsamidi import noteonevent

        midi_event = (1, 60, 127)
        data = (1, 60, 127, 0, 0)
        expected = (6, 1, 0, 253, (0, 0), (0, 0), (0, 0), data)
        self.assertEqual(expected, noteonevent(*midi_event))
    def midi_failure_accord(self):
        _akord = [0,3,6]
        akord = [self.st.base - 12 + x for x in _akord]
        for t in akord:
            alsaseq.output(noteonevent(1, t, 120))
        time.sleep(2)

        for t in akord:
            alsaseq.output(noteoffevent(1, t, 120))
Esempio n. 4
0
    def run(self):
        p1 = False
        p2 = False

        lastx1 = lastx2 = 0
        while True:
            with self.lock:
                (x1, y1) = self.pointA.getValues()
                (x2, y2) = self.pointB.getValues()
            if y1 == 0 and p1 == True:
                p1 = False
                #note = self._fromWIItoMIDI(52, 36, cwiid.IR_X_MAX, 0, int(lastx1))
                note = random.randint(1, 100) % 16 + 36
                alsaseq.output(
                    alsamidi.noteonevent(self.channel, int(note), 126))
                print note
#print "1: sending %d" % (int(note))

            elif y1 != 0:
                p1 = True
            else:
                pass

            if y2 == 0 and p2 == True:
                p2 = False
                #note = self._fromWIItoMIDI(52, 36, cwiid.IR_X_MAX, 0, int(lastx2))
                note = random.randint(1, 100) % 16 + 36
                alsaseq.output(
                    alsamidi.noteonevent(self.channel, int(note), 126))

#print "2: sending %d" % (int(note))

            elif y2 != 0:
                p2 = True
            else:
                pass
            lastx1 = x1
            lastx2 = x2

            time.sleep(self.sleepDelay)
    def midi_success_accord(self):
        _akord = [0, 12]
        akord = [self.st.base + 40 + x for x in _akord]
        for t in akord:
            alsaseq.output(noteonevent(1, t, 120))
        logger.info("midi_success, 1.faza")
        time.sleep(2)

        for t in akord:
            try:
                alsaseq.output(noteoffevent(1, t, 120))
            except Exception as e:
                logger.error("midi_success: " + str(e))
        logger.info("midi_success, posledna faza")
def play(predicted):
    import alsaseq, alsamidi

    alsaseq.client('andreas', 1, 1, True)
    alsaseq.connectto(1, 20, 0)
    alsaseq.start()

    for pitches in predicted.T:
        for i, on in enumerate(pitches):
            note = i + 50
            alsaseq.output(alsamidi.noteoffevent(0, note, 100))
            if on:
                alsaseq.output(alsamidi.noteonevent(0, note, 100))
        time.sleep(.1)
Esempio n. 7
0
    def run(self):
        p1 = False
        p2 = False

        lastx1 = lastx2 = 0
        while True:
            with self.lock:
                (x1, y1) = self.pointA.getValues()
                (x2, y2) = self.pointB.getValues()
            if y1 == 0 and p1 == True:
                p1 = False
                # note = self._fromWIItoMIDI(52, 36, cwiid.IR_X_MAX, 0, int(lastx1))
                note = random.randint(1, 100) % 16 + 36
                alsaseq.output(alsamidi.noteonevent(self.channel, int(note), 126))
                print note
                # print "1: sending %d" % (int(note))

            elif y1 != 0:
                p1 = True
            else:
                pass

            if y2 == 0 and p2 == True:
                p2 = False
                # note = self._fromWIItoMIDI(52, 36, cwiid.IR_X_MAX, 0, int(lastx2))
                note = random.randint(1, 100) % 16 + 36
                alsaseq.output(alsamidi.noteonevent(self.channel, int(note), 126))
                # print "2: sending %d" % (int(note))

            elif y2 != 0:
                p2 = True
            else:
                pass
            lastx1 = x1
            lastx2 = x2

            time.sleep(self.sleepDelay)
Esempio n. 8
0
def refresh_midi(data=None):
    global last_time

    import scikits.audiolab
    import alsaseq, alsamidi

    this_time = time.time()
    if last_time is None:
        last_time = this_time
    sleep = max(0, .2 - (this_time - last_time))

    print sleep

    while app.Pending():
        app.Dispatch()
    if data is not None:
        visualiser.on_training_update(data)
        out = data[-1, -esn.n_output_units:]
        out = (out - esn.teacher_shift) / esn.teacher_scaling
        notes_to_output = collections.defaultdict(list)
        for i, x in enumerate(out):
            # if i > 18:
            #     chan = 2
            #     note = {19: 29, 20: 31, 21: 33}[i]
            # elif i > 15:
            #     chan = 1
            #     note = {16: 36, 17: 40, 18: 44}[i]
            # else:
            #     chan = 0
            #     note = i + 69 - 24
            chan = 0
            note = i + 40
            alsaseq.output(alsamidi.noteoffevent(chan, note, 100))
            if x > .5:
                notes_to_output[chan].append((x, note))
        for chan, notes in notes_to_output.items():
            if len(notes) > 3:
                notes = sorted(notes)[:3]
            for _, note in notes:
                alsaseq.output(alsamidi.noteonevent(chan, note, 100))
        drawing_time = time.time() - this_time
        time.sleep(sleep)

    last_time = time.time() - drawing_time
Esempio n. 9
0
def refresh_midi(data=None):
    global last_time

    import scikits.audiolab
    import alsaseq, alsamidi
    
    this_time = time.time()
    if last_time is None:
        last_time = this_time
    sleep = max(0, .2 - (this_time - last_time))

    print sleep

    while app.Pending():
        app.Dispatch()
    if data is not None:
        visualiser.on_training_update(data)
        out = data[-1, -esn.n_output_units:]
        out = (out - esn.teacher_shift) / esn.teacher_scaling
        notes_to_output = collections.defaultdict(list)
        for i, x in enumerate(out):
            # if i > 18:
            #     chan = 2
            #     note = {19: 29, 20: 31, 21: 33}[i]
            # elif i > 15:
            #     chan = 1
            #     note = {16: 36, 17: 40, 18: 44}[i]
            # else:
            #     chan = 0
            #     note = i + 69 - 24
            chan = 0
            note = i + 40
            alsaseq.output(alsamidi.noteoffevent(chan, note, 100))
            if x > .5:
                notes_to_output[chan].append((x, note))
        for chan, notes in notes_to_output.items():
            if len(notes) > 3:
                notes = sorted(notes)[:3]
            for _, note in notes:
                alsaseq.output(alsamidi.noteonevent(chan, note, 100))
        drawing_time = time.time() - this_time
        time.sleep(sleep)

    last_time = time.time() - drawing_time
Esempio n. 10
0
 def playnote(self, note_idx):
     r = random.randint(0, 99)
     if r >= self.prob[note_idx]:
         self.publish(("printat", None,
                       (note_idx * self.print_note_width + 2, 3, ".")))
         time.sleep(self.duration / 1000)
         self.publish(("printat", None,
                       (note_idx * self.print_note_width + 2, 3, " ")))
     else:
         duration_on = self.durations[note_idx] * self.duration / 127
         chosen = self.getnote(self.interval_indexes[note_idx])
         vel = self.vel[note_idx]
         note = (0, chosen, vel)
         noteon = alsamidi.noteonevent(*note)
         noteoff = alsamidi.noteoffevent(*note)
         alsaseq.output(noteon)
         self.publish(("printat", None,
                       (note_idx * self.print_note_width + 2, 3, "*")))
         time.sleep(duration_on / 1000)
         alsaseq.output(noteoff)
         self.publish(("printat", None,
                       (note_idx * self.print_note_width + 2, 3, " ")))
         time.sleep((self.duration - duration_on) / 1000)
Esempio n. 11
0
from alsamidi import noteonevent, noteoffevent

#alsaseq.client( 'MIDI through', 1, 1, False )
#alsaseq.connectfrom( 1, 129, 0 )
#alsaseq.connectto( 0, 130, 0 )

alsaseq.client( 'Simple', 1, 1, True )
alsaseq.connectto( 1, 128, 0 )

alsaseq.start()

_akord=[0,4,7]

akord=[i+12*j for i in _akord for j in range(1)]

for base in range(40):
    events=[(1, 40+base+i, 120) for i in akord]

    noteons=[noteonevent(*event) for event in events]
    noteoffs=[noteoffevent(*event) for event in events]

    s=raw_input("stlac enter")
    for noteon in noteons:
        alsaseq.output(noteon)
    time.sleep(1)
    for noteoff in noteoffs:
        alsaseq.output(noteoff)
    time.sleep(0.2)
time.sleep(10)
#alsaseq.output( (6, 1, 0, 1, (1, 0), (0, 0), (0, 0), (0, 60, 127, 0, 100)) )
Esempio n. 12
0
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x63, FX2_SEND)) )
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x62, 0x48)) )
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x05, 0x00)) )
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x26, 0x05)) )
#  time.sleep(0.5)

#alsaseq.output( (6, 1, 0, 1, (5, 0), (0, 0), (0, 0), (0, 60, 127, 0, 100)) )  
  
alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, alsamidi.SND_SEQ_QUEUE_DIRECT, (0, 0), (0, 0), (0, 0), (0xB0 + (CHANNEL-1), 0x63, FX2_SEND,   0xB0 + (CHANNEL-1), 0x62, 0x48,   0xB0 + (CHANNEL-1), 0x05,0x00,   0xB0 + (CHANNEL-1), 0x26,0x05)) )   


time.sleep(1000)


# mute group 2 -> muted
msg_part1 = alsamidi.noteonevent(CHANNEL-1, MUTE_GRP2_NOTE, 0x40)
msg_part2 = alsamidi.noteoffevent(CHANNEL-1, MUTE_GRP2_NOTE, 0)
alsaseq.output(msg_part1)
alsaseq.output(msg_part2)

time.sleep(2)

# mute group 2 -> unmuted
msg_part1 = alsamidi.noteonevent(CHANNEL-1, MUTE_GRP2_NOTE, 0x40-1)
msg_part2 = alsamidi.noteoffevent(CHANNEL-1, MUTE_GRP2_NOTE, 0)
alsaseq.output(msg_part1)
alsaseq.output(msg_part2)



time.sleep(1000)
 def on(self, vel=None, chan=None):
     alsaseq.output(alsamidi.noteonevent(self.chan, self.key, self.vel))
     self.active = True
Esempio n. 14
0
alsaseq.connectto(0, 128, 0)
alsaseq.connectto(0, 130, 0)
alsaseq.connectto(0, 131, 0)
alsaseq.start()

time.sleep(1)

# Instrument Select
event = alsamidi.pgmchangeevent(0, 0)
alsaseq.output(event)

# Raw Note ON:
alsaseq.output((6, 1, 0, 0, (0, 0), (0, 0), (0, 0), (0, 70, 127, 0, 100)))

# Note ON Event
event = alsamidi.noteonevent(0, 66, 120)
alsaseq.output(event)

control = 74
for i in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15):
    value = i * 16
    alsaseq.output((alsaseq.SND_SEQ_EVENT_CONTROLLER, 1, 0, 0, (0, 0), (0, 0),
                    (0, 0), (0, 0, 0, 0, control, value)))
    time.sleep(0.04)

for i in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15):
    value = (15 - i) * 16
    alsaseq.output((alsaseq.SND_SEQ_EVENT_CONTROLLER, 1, 0, 0, (0, 0), (0, 0),
                    (0, 0), (0, 0, 0, 0, control, value)))
    time.sleep(0.04)
Esempio n. 15
0
 def midi_play_tone(x):
     if self.tones_amount < self.st.max_tone_amount:
         alsaseq.output(noteonevent((1, x, 120)))
         self.tones_amount += 1
Esempio n. 16
0
def PlayNote(note,velocity=127):
    print "playnote", note, velocity
    alsaseq.output(alsamidi.noteonevent( 0, note, velocity ))
Esempio n. 17
0
def PlayNote(note):
    alsaseq.output(alsamidi.noteonevent( 0, note, 127 ))
def midi_play(notes):
    for note in notes:
        alsaseq.output(alsamidi.noteonevent(note.channel, note.pitch, 100))
    time.sleep(SLEEP_TIME)
    for note in notes:
        alsaseq.output(alsamidi.noteoffevent(note.channel, note.pitch, 0))
 def midi_play_tone(self, x):
     if len(self.tones_playing) < self.st.max_tone_amount:
         alsaseq.output(noteonevent(1, x, 120))
         self.tones_playing.append(x)
Esempio n. 20
0
def PlayNote(note):
    alsaseq.output(alsamidi.noteonevent(0, note, 127))
Esempio n. 21
0
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x63, FX2_SEND)) )
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x62, 0x48)) )
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x05, 0x00)) )
#  alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (0x26, 0x05)) )
#  time.sleep(0.5)

#alsaseq.output( (6, 1, 0, 1, (5, 0), (0, 0), (0, 0), (0, 60, 127, 0, 100)) )

alsaseq.output(
    (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, alsamidi.SND_SEQ_QUEUE_DIRECT,
     (0, 0), (0, 0), (0, 0),
     (0xB0 + (CHANNEL - 1), 0x63, FX2_SEND, 0xB0 + (CHANNEL - 1), 0x62, 0x48,
      0xB0 + (CHANNEL - 1), 0x05, 0x00, 0xB0 + (CHANNEL - 1), 0x26, 0x05)))

time.sleep(1000)

# mute group 2 -> muted
msg_part1 = alsamidi.noteonevent(CHANNEL - 1, MUTE_GRP2_NOTE, 0x40)
msg_part2 = alsamidi.noteoffevent(CHANNEL - 1, MUTE_GRP2_NOTE, 0)
alsaseq.output(msg_part1)
alsaseq.output(msg_part2)

time.sleep(2)

# mute group 2 -> unmuted
msg_part1 = alsamidi.noteonevent(CHANNEL - 1, MUTE_GRP2_NOTE, 0x40 - 1)
msg_part2 = alsamidi.noteoffevent(CHANNEL - 1, MUTE_GRP2_NOTE, 0)
alsaseq.output(msg_part1)
alsaseq.output(msg_part2)

time.sleep(1000)
Esempio n. 22
0
alsaseq.connectto(0, 128, 0)
alsaseq.connectto(0, 130, 0)
alsaseq.connectto(0, 131, 0)
alsaseq.start()

time.sleep(1)

# Instrument Select
event = alsamidi.pgmchangeevent(0, 0)
alsaseq.output(event)

# Raw Note ON:
alsaseq.output((6, 1, 0, 0, (0, 0), (0, 0), (0, 0), (0, 70, 127, 0, 100)))

# Note ON Event
event = alsamidi.noteonevent(0, 66, 120)
alsaseq.output(event)

control = 74
for i in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15):
    value = i * 16
    alsaseq.output((alsaseq.SND_SEQ_EVENT_CONTROLLER, 1, 0, 0, (0, 0), (0, 0), (0, 0), (0, 0, 0, 0, control, value)))
    time.sleep(0.04)

for i in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15):
    value = (15 - i) * 16
    alsaseq.output((alsaseq.SND_SEQ_EVENT_CONTROLLER, 1, 0, 0, (0, 0), (0, 0), (0, 0), (0, 0, 0, 0, control, value)))
    time.sleep(0.04)


for i in (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12):