def test(self): from alsamidi import noteevent midi_event = (1, 60, 127, 1000, 10) data = (1, 60, 127, 0, 10) expected = (5, 1, 0, 0, (1, 0), (0, 0), (0, 0), data) self.assertEqual(expected, noteevent(*midi_event))
def construye( ritmo, tempo, compases, start=0 ): 'Construye lista de eventos a partir de ritmo.' def itotiempo( i ): 'Regresa tiempo dentro del compas.' return i * tbeat * numerador / numbeats + start tbeat = int( 60. / tempo * 1000 ) numerador = ritmo[ 1 ][ 0 ] numbeats = ritmo[ 1 ][ 1] inicios = list(map( itotiempo, list(range( numbeats * compases)) )) duracion = int( tbeat * 0.9 ) instrumentos = ritmo[ 2 ] eventos = [] for ch, pgm, timbre, vel, notas in instrumentos: if pgm: eventos.append( alsamidi.pgmchangeevent( ch, pgm, start=0 ) ) for ibeat, nota in enumerate( notas * compases ): if nota != ' ': eventos.append( alsamidi.noteevent( ch, timbre, vel, inicios[ ibeat ], duracion ) ) return eventos
def construye(ritmo, tempo, compases, start=0): 'Construye lista de eventos a partir de ritmo.' def itotiempo(i): 'Regresa tiempo dentro del compas.' return i * tbeat * numerador / numbeats + start tbeat = int(60. / tempo * 1000) numerador = ritmo[1][0] numbeats = ritmo[1][1] inicios = list(map(itotiempo, list(range(numbeats * compases)))) duracion = int(tbeat * 0.9) instrumentos = ritmo[2] eventos = [] for ch, pgm, timbre, vel, notas in instrumentos: if pgm: eventos.append(alsamidi.pgmchangeevent(ch, pgm, start=0)) for ibeat, nota in enumerate(notas * compases): if nota != ' ': eventos.append( alsamidi.noteevent(ch, timbre, vel, inicios[ibeat], duracion)) return eventos