def init_alsa(self): # prepare alsaseq device_no = self.options[ "midi_device_no"] # find out using aconnect or aconnectgui alsaseq.client('Recorder', 1, 0, True) alsaseq.connectfrom(0, device_no, 0) alsaseq.start()
def __init__(self, addr=None, channel=1): self.ctrl_param = 98 self.channel = channel - 1 alsaseq.client('Aeolus-OSC', 0, 1, True) alsaseq.start() self.src = (alsaseq.id(), 0) log.info('I am %s:%s' % (str(self.src[0]), str(self.src[1]))) self.update_connection(addr) # from help(alsaseq): # # ALSA events are returned as a tuple with 8 elements: # (type, flags, tag, queue, time stamp, source, destination, data) # # Some elements are also tuples: # time = (seconds, nanoseconds) # source, destination = (client, port) # data = ( varies depending on type ) # # See DATA section below for event type constants. # # This API is nuts. # TODO should send events to subscribed ports not directly to aeolus self.presets = None
def music(): global esn, visualiser train_skip = sys.argv[1] test_skip = sys.argv[2] input, output, esn = test_data.bach() n_forget_points = 0 alsaseq.client('andreas', 1, 1, True) alsaseq.connectto(1, 20, 0) alsaseq.start() visualiser = Visualiser(esn) if len(sys.argv) < 4: state_matrix = esn.train(input, output, n_forget_points=n_forget_points, callback_every=int(train_skip), callback=refresh_midi) else: with open(sys.argv[3]) as f: esn.unserialize(cPickle.load(f)) visualiser.set_weights() esn.reset_state() esn.noise_level = 0 print 'test' estimated_output = esn.test(input, callback=refresh_midi, n_forget_points=n_forget_points, callback_every=int(test_skip)) error = nrmse(estimated_output, output) print 'error: %s' % error
def playback(): 'Start playing events.' global playing, outgoing, incoming playing = True incoming = [] outgoing = merge(seq.tracks) alsaseq.start() print('playing') print(seq.info())
def playback(): "Start playing events." global playing, outgoing, incoming playing = True incoming = [] outgoing = merge(seq.tracks) alsaseq.start() print("playing") print(seq.info())
def __init__(self, lock, volumePoint, notePoint, channel): threading.Thread.__init__(self) self.stop = threading.Event() self.volumePoint = volumePoint self.notePoint = notePoint self.channel = channel self.lock = lock self.sleepDelay = 0.03 alsaseq.client("therminal", 0, 1, False) alsaseq.start()
def __init__(self, lock, pointA, pointB, channel): threading.Thread.__init__(self) self.stop = threading.Event() self.pointA = pointA self.pointB = pointB self.lock = lock self.channel = channel self.sleepDelay = 0.03 alsaseq.client("druminal", 0, 1, False) alsaseq.start()
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)
def __init__(self, invoker, env, settings): BaseExhibit.__init__(self, invoker, env, settings) self.env.game_load.listen_once(self.reset_game) self.env.game_load.listen_once(self.qr_register) os.system("pkill timidity") os.system("timidity -iA -Os &") alsaseq.client( 'Simple', 1, 1, True ) alsaseq.connectto( 1, 128, 0 ) alsaseq.start() self.st.max_tone_amount = 3 self.tones_amount = 0
def run(self): logging.info("Starting MIDI clock queue") self.enqueue_events() alsaseq.start() while self.keep_running: # not using alsaseq.syncoutput() here, as we would not be fast enough to enqueue more events after # the queue has flushed, thus sleep for half the approximate time the queue will need to drain time.sleep(self.enqueue_at_once / 2 * self.delay) status, time_t, events = alsaseq.status() if events >= self.enqueue_at_once: #logging.info("more than 24*4 events queued, skipping enqueue") continue self.enqueue_events() alsaseq.stop() logging.info("MIDI clock queue stopped")
def run(self): import select alsaseq.client(appinfo.name, self.num_inports, self.num_outports, True) self.start_time = datetime.now() alsaseq.start() log.debug("ALSA sequencer started") alsafd = alsaseq.fd() while not self.join_req: fds_ready = select.select([alsafd], [], [], 0.1) if alsaseq.inputpending(): raw_event = alsaseq.input() new_event = self.create_event(raw_event) self.dispatch_event(new_event)
def run(self): import select alsaseq.client(appinfo.name, self.num_inports, self.num_outports, True) self.start_time = datetime.now() alsaseq.start() log.debug("ALSA sequencer started") alsafd = alsaseq.fd() while not self.join_req: fds_ready = select.select([alsafd], [], [], 0.1) if alsaseq.inputpending(): raw_event = alsaseq.input() new_event = self.create_event(raw_event) self.dispatch_event(new_event) alsaseq.stop() alsaseq.close()
def clickThreadRun(self): def noteOff(time): time_split = math.modf(time) time_i = int(time_split[1]) time_f = int(time_split[0] * 1e9) # print (time_i, time_f) return (7, 1, 0, 0, (time_i, time_f), (130, 0), (131, 0), (9, 75, 0, 0, 0)) def noteOn(time, v, instrument): time_split = math.modf(time) time_i = int(time_split[1]) time_f = int(time_split[0] * 1e9) # print (time_i, time_f) return (6, 1, 0, 0, (time_i, time_f), (130, 0), (131, 0), (9, instrument, v, 0, 0)) clicks = self.songStructure.getAllClicksSecs() clicks.sort() lookAheadTime = 10 # seconds self.clickStartTime = time.time() alsaseq.start() """ print "-=---------------------------" print self.songStructure.totalNumMeasures() print self.songStructure.totalSecsLength() print len(clicks) print "-=---------------------------" """ totalSongLenSecs = self.songStructure.totalSecsLength() for c in clicks: alsaseq.output(noteOn(c[0], 127, c[1])) if self.stopClick: break while c[0] > (time.time() - self.clickStartTime) + lookAheadTime: time.sleep(0.5) while (time.time() - self.clickStartTime) < totalSongLenSecs: time.sleep(0.5) print "done with song!" alsaseq.stop() self.clickStartTime = 0 self.stopClick = True
def __init__(self, invoker, env, settings): BaseExhibit.__init__(self, invoker, env, settings) self.env.game_load.listen_once(self.reset_game) self.env.game_load.listen_once(self.qr_register) try: logger.info(os.system("pgrep timidity")) logger.info(os.system("pkill timidity")) logger.info(os.system("timidity -iA -Os -B5,12 &")) #logger.info(os.system("timidity -iA -Os")) time.sleep(2) #essential for good connection alsaseq.client( 'Simple', 1, 1, True ) alsaseq.connectto( 1, 128, 0 ) alsaseq.start() logger.info("timidity is ok. (i hope)") except Exception as e: logger.error("timidity" + str(e)) self.st.max_tone_amount = 3 self.tones_playing = []
def main(dest_client, file_name, display=False): seq = alsamidi.Seq() seq.read(file_name) events = alsamidi.merge(seq.tracks) seq.info() print(len(events), 'events') alsaseq.client('aseqplay', 0, 1, 1) alsaseq.connectto(0, dest_client, 0) for channel in range(16): alsaseq.output(alsamidi.pgmchangeevent(channel, 0)) alsaseq.start() for event in events: if display: print(event) alsaseq.output(event) alsaseq.syncoutput()
import alsaseq import time 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)
def play(eventos): 'Envia lista de eventos a la cola del secuenciador.' alsaseq.start() for evento in eventos: alsaseq.output(evento) alsaseq.syncoutput()
def __init__(self, client_name="Zynthian_gui"): alsaseq.client(client_name, 1, 1, True) #alsaseq.connectto(0,130,0) alsaseq.start()
def play( eventos ): 'Envia lista de eventos a la cola del secuenciador.' alsaseq.start() for evento in eventos: alsaseq.output( evento ) alsaseq.syncoutput()
#!/usr/bin/env python3 # amiditimer.py - Tom Clayton # Connect input and output to alsa midi streams and this program will # send a message out and time how long it takes for it to return. import alsaseq import sys alsaseq.client('Midi Timer', 1, 1, True) # alsaseq event: # (type, flags, tag, queue, time stamp, source, destination, data) # data = (channel, note, velocity, start, duration) out_event = (6, 1, 0, 1, (0, 0), (0, 0), (0, 0), (0, 60, 127, 0, 0)) input("Midi Timer, connect then hit enter to start.") alsaseq.output(out_event) alsaseq.start() while True: if alsaseq.inputpending(): event = alsaseq.input() if event[0] == 6: print(event[4][1] / 1000000, " ms") break
def __init__(self, client_name="Zynthian_gui"): alsaseq.client(client_name,1,0,True) #alsaseq.connectto(0,130,0) alsaseq.start()