def __init__(self, preferred_port=None): super().__init__() self.keep_running = True self.client_id = 0 self.client_port = 0 self.time_s = 0 self.time_ns = 0 self.add_s = 0 self.add_ns = 0 self.enqueue_at_once = 24 # this call causes /proc/asound/seq/clients to be created alsaseq.client('MidiClock', 0, 1, True) client_name = "" for client in iter_alsa_seq_clients(): self.client_id = client[0] client_name = client[1] self.client_port = client[2][0] logging.info("found port {} at {}:{}".format( client_name, self.client_id, self.client_port)) if client_name == preferred_port: break logging.info("Using port {} at {}:{}".format(client_name, self.client_id, self.client_port)) alsaseq.connectto(0, self.client_id, self.client_port)
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 main(): cliente_destino = int( sys.argv[1] ) archivo = sys.argv[2] trios = [] for e in sys.argv[3:]: n, tempo, compases = list(map( int, e.split() )) trios.append( ( n, tempo, compases ) ) import alsaseq alsaseq.client( 'Reproductor', 0, 1, True ) alsaseq.connectto( 0, cliente_destino, 0 ) alsamidi.queue = 1 def play( eventos ): 'Envia lista de eventos a la cola del secuenciador.' alsaseq.start() for evento in eventos: alsaseq.output( evento ) alsaseq.syncoutput() ritmos = lee( archivo ) print(len(ritmos), 'ritmos:', [x[0] for x in ritmos]) eventos = [] end = 0 for trio in trios: n, tempo, compases = trio ritmo = ritmos [ n ] eventos.extend( construye( ritmo, tempo, compases, end ) ) print(str( end ).rjust( 5 ), str( compases ).rjust( 3 ), ritmo[ 0 ]) end = end + compases * int( 60. / tempo * 1000 ) * ritmo[1][0] play( eventos )
def main(): se = ServoEvent() parser = MusicParser() alsaseq.client('RoboWhistle PassThrough', 1, 1, False) # Set up a new ALSA channel alsaseq.connectfrom( 1, 129, 0) # Midi file input needs to be sent in to channel 129 # Backup ALSA channel to run on port 128. Can use either a virtual synth (e.g. Timidity or a physical MIDI keyboard) alsaseq.connectto(1, 128, 0) srv = ServoEvent() srv.ResetServoEvent() #To enter FreePlay mode provide any argument when running the program; if left blank AutoPlay will proceed automaticlly if len(sys.argv) is 2: print "Entering FreePlay Mode" play = FreePlay() play.ManualPlay() else: print str(len(sys.argv)) while 1: if alsaseq.inputpending(): # ALSA queue event = alsaseq.input() # Pop event from top of the queue eventPitch = event[7][ 1] # Pitch of the note that needs to be played parsedNote = parser.AnalyseSingleNote(eventPitch % 12) if parsedNote is None: alsaseq.output( event ) # Event is unplayable by the whistle, forward it to the synthesiser else: se.PlayNoteEvent(parsedNote) # Pass item for playing
def main(): cliente_destino = int(sys.argv[1]) archivo = sys.argv[2] trios = [] for e in sys.argv[3:]: n, tempo, compases = list(map(int, e.split())) trios.append((n, tempo, compases)) import alsaseq alsaseq.client('Reproductor', 0, 1, True) alsaseq.connectto(0, cliente_destino, 0) alsamidi.queue = 1 def play(eventos): 'Envia lista de eventos a la cola del secuenciador.' alsaseq.start() for evento in eventos: alsaseq.output(evento) alsaseq.syncoutput() ritmos = lee(archivo) print(len(ritmos), 'ritmos:', [x[0] for x in ritmos]) eventos = [] end = 0 for trio in trios: n, tempo, compases = trio ritmo = ritmos[n] eventos.extend(construye(ritmo, tempo, compases, end)) print(str(end).rjust(5), str(compases).rjust(3), ritmo[0]) end = end + compases * int(60. / tempo * 1000) * ritmo[1][0] play(eventos)
def Open(self, src_list=[], dest_list=[]): ''' src_list is a list of src ports to connect to. From -i#,# dest_list is a list of dest ports to connect to. From -o#,#, ''' print('opening alsaseq client') junk_None = alsaseq.client( 'midiroute', # name of virtual client 1, #num in ports 1, #num out ports False) # create_queue Y/N - rx buf? # there is also connectto(), connectfrom() funcs... # these appear to be for connecting client() to other ports # following input port, output port appear to be 0 for input, # 1 for output. for src_i in src_list: print('in:%d' % (src_i)) alsaseq.connectfrom(0, # input port src_i, # src client 0) # src port for dest_i in dest_list: print('out:%d' % (dest_i)) alsaseq.connectto(1, # output port(first one of ours?) dest_i, # dest client 0) # dest port # connect ins and outs based on string comparisons: # see ourAlsaIn()/Out() above for setting your string connect matches #if len(src_list) == 0 and len(dest_list) == 0: if self.auto_midi_conn: # -a[0|1] option, default 1 on print('scanning Alsa Midi Inputs') lst = AlsaSeq_List(0) # list inputs(Midi Keys for ex) for m in lst: if ourAlsaIn(m): print('connect input client %3d %-26s port %d %s' % (m.client_id,m.client_name, m.port_id,m.port_name)) alsaseq.connectfrom(m.port_id, # our port, first input is 0 m.client_id, # 28 for example m.port_id) # 0 for example print('scanning Alsa Midi Outputs') lst = AlsaSeq_List(1) # list outputs(synth ex) for m in lst: if ourAlsaOut(m): print('connect output client %3d %-26s port %d %s' % (m.client_id,m.client_name, m.port_id,m.port_name)) alsaseq.connectto(1, # our first output port is 1 now m.client_id, # 28 for example m.port_id) # 0 for example # how do we tell if successful? This is returning None? # it calls exit(1) if fails, I guess client is not expected # to fail... self.mDevIn = True if self.mDevIn != None: return True # ok print('fail!') return False # no open
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 __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()
def open(self, preferred_name=None, preferred_port=0): clients_found = False for id, name, ports in self.iter_alsa_seq_clients(): clients_found = True logging.debug("midi device %d: %s [%s]", id, name, ','.join([str(x) for x in ports])) if (preferred_name is None and name != "Midi Through") or name == preferred_name: self.client_id = id if preferred_port not in ports: preferred_port = ports[0] logging.warning("Preferred port not found, using %d", preferred_port) self.client_port = preferred_port break if self.client_id is None: if clients_found: raise RuntimeError( f"Requested device {preferred_name} not found") else: raise RuntimeError("No sequencers found") logging.info("Using device %s at %d:%d", name, self.client_id, self.client_port) alsaseq.connectto(0, self.client_id, self.client_port)
#!/usr/bin/python import sys import alsaseq import alsamidi alsaseq.client('ZynthianGUI', 0, 1, True) alsaseq.connectto( 0, 128, 0 ) alsaseq.connectto( 0, 130, 0 ) alsaseq.connectto( 0, 131, 0 ) alsaseq.start() # Instrument Select note=sys.argv[1] print "Program " + note event=alsamidi.pgmchangeevent(0, int(note)) alsaseq.output(event)
nritmo = int(letra) print("{:2} {}".format(nritmo, ritmos[nritmo][0])) elif letra == "n": number = int(input()) if number < len(ritmos): nritmo = number print("{:2} {}".format(nritmo, ritmos[nritmo][0])) elif letra == "t": tempo = int(input()) print("tempo:", tempo) rechazados = (alsaseq.SND_SEQ_EVENT_CLOCK, alsaseq.SND_SEQ_EVENT_SENSING) alsaseq.client("ReproductorGrabador", 1, 1, 1) alsaseq.connectfrom(0, source_cliente, 0) alsaseq.connectto(1, dest_cliente, 0) alsaseq.start() pgmchangevoz1 = alsamidi.pgmchangeevent(0, voz1) pgmchangevoz2 = alsamidi.pgmchangeevent(1, voz2) alsaseq.output(pgmchangevoz1) if voz2: alsaseq.output(pgmchangevoz2) nlibres = 100 import kbhit kbhit.unbuffer_stdin() vivo = 1 seq = alsamidi.Seq() try: fd = alsaseq.fd()
FX2_SEND = 0x01 FX3_SEND = 0x02 FX4_SEND = 0x03 CHANNEL=1 # connect to qu-16 usb #alsaseq.connectto( 0, 28, 0 ) alsaseq.client( 'quPy', 1, 1, False ) #alsaseq.connectfrom( 0, 28, 0 ) #qu16_conn = alsaseq.connectto( 1, 11, 0 ) # qu16 #alsaseq.connectto( 1, 28, 0 ) # qu16 #sys.stderr.write(str(qu16_conn) + "\n") alsaseq.connectto( 1, 129, 0 ) # midi monitor alsaseq.start() # send tap #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x63, FX2_SEND)) ) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x62, 0x48)) ) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x05, 0x00)) ) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x26, 0x05)) ) #time.sleep(0.5) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x63, FX2_SEND)) )
exit(2) return p # ============================================================================ args = sys.argv[1:] args.append("-m") # args.append('20:14:12:17:01:67') args.append('20:14:12:17:02:47') params = parseArgs(args) # initialize ALSA alsaseq.client( 'MidiCube', 1, 1, False ) if params.alsaOut is not None: (client, port) = params.alsaOut alsaseq.connectto(0, client, port) if params.alsaIn is not None: (client, port) = params.alsaIn alsaseq.connectfrom(0, client, port) # connect to bluetooth device sock = com.connect(params.btMAC) if not sock: logging.error('connection to MIDI cube failed') exit(-1) listener = Listener(sock, params.btMAC) scheduler = Scheduler(params) alsain = alsaInput() scheduler.start()
FX2_SEND = 0x01 FX3_SEND = 0x02 FX4_SEND = 0x03 CHANNEL = 1 # connect to qu-16 usb #alsaseq.connectto( 0, 28, 0 ) alsaseq.client('quPy', 1, 1, False) #alsaseq.connectfrom( 0, 28, 0 ) #qu16_conn = alsaseq.connectto( 1, 11, 0 ) # qu16 #alsaseq.connectto( 1, 28, 0 ) # qu16 #sys.stderr.write(str(qu16_conn) + "\n") alsaseq.connectto(1, 129, 0) # midi monitor alsaseq.start() # send tap #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x63, FX2_SEND)) ) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x62, 0x48)) ) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x05, 0x00)) ) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x26, 0x05)) ) #time.sleep(0.5) #alsaseq.output( (alsaseq.SND_SEQ_EVENT_NONREGPARAM, 1, 0, 1, (0,0), (0,0), (0,0), (CHANNEL-1, #0xB0 + (CHANNEL-1), 0x63, FX2_SEND)) )
# # 1) Bandwidth (Sound control 6) (no. 75) # This increases or decreases the bandwidth of instruments. The default parameter is 64. # # 2) Modulation amplitude (Sound control 7) (no. 76) # This decreases the amplitude of modulators on ADsynth. The default parameter is 127. # # 3) Resonance Center Frequency (Sound control 8) (no. 77) # This changes the center frequency of the resonance. # # 4) Resonance Bandwidth (Sound control 9) (no. 78) # This changes the bandwidth of the resonance. #-------------------------------------- alsaseq.client('ZynthianGUI', 0, 1, True) 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)
def is_dissonant(note, memory): pitches = [False] * 5 pitches[2] = True for memory_note in memory: if memory_note and abs((note.pitch % 12) - (memory_note.pitch % 12)) <= 2: pitches[(memory_note.pitch % 12) - (note.pitch % 12)] = True # f**k science return ((pitches[0] and pitches[1] and pitches[2]) or (pitches[1] and pitches[2] and pitches[3]) or (pitches[2] and pitches[3] and pitches[4])) alsaseq.client('arp', 1, 1, False) alsaseq.connectto(1, 20, 0) def sigint_handler(signal, frame): finish() sys.exit(1) def finish(): curses.nocbreak() curses.echo() curses.endwin() print 'cleaning up' for channel in range(16): for pitch in range(128): alsaseq.output(alsamidi.noteoffevent(channel, pitch, 0)) signal.signal(signal.SIGINT, sigint_handler)
# ============================================================================ # signal.signal(signal.SIGTERM, sigterm_handler) args = sys.argv[1:] args.append("-m") args.append('20:14:12:17:01:67') #args.append('20:14:12:17:02:47') params = parseArgs(args) # initialize ALSA alsaseq.client('LaserGun', 1, 1, False) if params.alsaOut is not None: (client, port) = params.alsaOut alsaseq.connectto(0, client, port) if params.alsaIn is not None: (client, port) = params.alsaIn alsaseq.connectfrom(0, client, port) # connect to bluetooth device sock = com.connect(params.btMAC) if not sock: logging.error('connection to laser gun failed') exit(2) listener = Listener(sock) scheduler = Scheduler(params) alsain = alsaInput() scheduler.start()
if __name__ == "__main__": parser = argparse.ArgumentParser(PROC_NAME) parser.add_argument("-a", "--alsa-port", default=DEFAULT_TARGET_ALSA_PORT, type=str, help="Specify ALSA port to connect to, default: %s" % DEFAULT_TARGET_ALSA_PORT) parser.add_argument("-p", "--processor", type=str, help="Specify Sushi's processor to benchmark") parser.add_argument("-n", "--notes", type=int, nargs='+', default=[60], help="List of MIDI note numbers to send, default: %s" % DEFAULT_MIDI_NOTES) parser.add_argument("-d", "--duration", default=DEFAULT_NOTE_DURATION, type=float, help="Note duration in seconds, default: %s" % DEFAULT_NOTE_DURATION) args = parser.parse_args() grpc_helper = SushiRPChelper(args.processor) alsaseq.client(PROC_NAME, 0, 1, True) alsaseq.connectto(0, get_alsa_port_by_name(args.alsa_port), 0) alsaseq.start() grpc_helper.reset_timings() time.sleep(0.5) timings_no_load = grpc_helper.get_timings() print("Processor load without Note ONs: %s avg, %s max" % (timings_no_load.average, timings_no_load.max)) while (True): grpc_helper.reset_timings() for note in args.notes: alsaseq.output(noteonevent(0, note, 127)) time.sleep(args.duration) timings_end = grpc_helper.get_timings() for note in args.notes:
nritmo = int(letra) print('{:2} {}'.format(nritmo, ritmos[nritmo][0])) elif letra == 'n': number = int(input()) if number < len(ritmos): nritmo = number print('{:2} {}'.format(nritmo, ritmos[nritmo][0])) elif letra == 't': tempo = int(input()) print('tempo:', tempo) rechazados = (alsaseq.SND_SEQ_EVENT_CLOCK, alsaseq.SND_SEQ_EVENT_SENSING) alsaseq.client('ReproductorGrabador', 1, 1, 1) alsaseq.connectfrom(0, source_cliente, 0) alsaseq.connectto(1, dest_cliente, 0) alsaseq.start() pgmchangevoz1 = alsamidi.pgmchangeevent(0, voz1) pgmchangevoz2 = alsamidi.pgmchangeevent(1, voz2) alsaseq.output(pgmchangevoz1) if voz2: alsaseq.output(pgmchangevoz2) nlibres = 100 import kbhit kbhit.unbuffer_stdin() vivo = 1 seq = alsamidi.Seq() try: fd = alsaseq.fd() thso = threading.Thread(target=supplyoutput)
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 do_connect(addr): log.info('Connecting to %d:%d' % addr) alsaseq.connectto(0, addr[0], addr[1])
from pyseq.midiin import MidiInCtrl from pyseq.model import SequencerModel from pyseq.view import SequencerView FROM = [(28, 0), (32, 0)] TO = [(129, 0), (32, 0)] alsaseq.client("pyseq", 1, 1, 0) for midiin in FROM: alsaseq.connectfrom(0, midiin[0], midiin[1]) for midiout in TO: alsaseq.connectto(1, midiout[0], midiout[1]) def main(): logging.basicConfig(filename="debug.log", level=logging.DEBUG) midi_receiver = MidiInCtrl() view = SequencerView() sequencer = SequencerModel() # MidiIN -> Sequencer # MidiIN -> View midi_receiver.subscribe(sequencer.in_q) midi_receiver.subscribe(view.in_q) # Keyboard -> Sequencer # Keyboard -> MidiIn