def playSeconds(self, n_sec): """ Recibe la cantiad de segundos a reproducir desde la posición actual y los reproduce. Si la cantidad de segundos parametrizada no es un número válido, se lanza la excepción ValueError. """ duracion = 0 acordes = ListaEnlazada() reproductor = pysounds.SoundPlayer(len(self.tracks)) try: duracion = float(n_sec) except ValueError: raise ValueError("Parámetros inválidos.") for pos in range(self.cursor, len(self.marks)): tiempo, notas = self.marks[pos] duracion -= tiempo if duracion>=0: self.notasALista(tiempo, notas, acordes) else: residual = duracion + tiempo self.notasALista(residual, notas, acordes) break try: for track,tiempo in acordes: reproductor.play_sounds(track,tiempo) except OSError: raise OSError("Ocurrió un problema en la reproducción.")
def _reproducir(self, lista_tiempos, segundos=-1): """El metodo reproduce una lista de marcas de tiempos por una cantidad de segundos dada por parametro. Si la cantidad de segundos no entra como parametro, la misma toma el valor de '-1', de esta manera no se tiene en cuenta el tiempo de reproduccion. Pre: lista_tiempos (list): Es una lista que contiene objetos de la clase MarcasTiempo. segundos (float): Es la cantidad de segundos que deben reproducirce. Si parametro no es indicado entonces se reproduce toda la lista_tiempos sin limitacion.""" sp = pysounds.SoundPlayer(len(self.sonidos)) a_reproducir = [] if segundos == -1: for t in lista_tiempos: notas = self.obtener_sonidos(t) tiempo = t.obtener_tiempo() a_reproducir.append((notas, tiempo)) else: tiempo_acumulado = 0 for t in lista_tiempos: notas = self.obtener_sonidos(t) tiempo = t.obtener_tiempo() if tiempo_acumulado + tiempo <= segundos: a_reproducir.append((notas, tiempo)) tiempo_acumulado += tiempo continue a_reproducir.append((notas, segundos - tiempo_acumulado)) break for nota, tiempo in a_reproducir: sp.play_sounds(nota, tiempo) sp.close()
def play(self, marcas, segundos=None): """Reproduce la cancion.\n ->marcas(int): es la cantidad de marcas que se reproduciran.\n ->segundos(int): es la cantidad de segundos que se reproduciran.\n Es un parametro opcional.""" if self.editor.timeline.len == 0: print("No hay marcas para reproducir") reproductor = soundPlayer.SoundPlayer(len(self.editor.tracks)) actual = self.editor.cursor cont_marcas = 0 cont_seg = 0 while actual is not None and cont_marcas < marcas: mark = actual.dato if segundos: if cont_seg == segundos: return cont_seg += mark.duracion lista_aux = [] for i in range(len(self.editor.tracks)): (funcion, frecuencia, volumen) = self.editor.tracks[i] if mark.tracks.get((funcion, frecuencia, volumen), False) == "#": lista_aux.append( self.editor.sound.get(funcion)(frecuencia, volumen)) reproductor.play_sounds(lista_aux, mark.duracion) actual = actual.prox cont_marcas += 1
def reproducir_tiempos(self,lista_tiempos=False,segundos=False): '''Toma como parametro una lista_tiempos y/o segundos los cuales se van reproducir''' sp=pysounds.SoundPlayer(2) a_reproducir=[] if not lista_tiempos: lista_tiempos=self.tiempos if not segundos: for t in lista_tiempos: print('caca') #buena forma de ver donde esta el error jajajajaj notas=t.obtener_nota_obj() tiempo=t.obtener_tiempo() a_reproducir.append((notas,tiempo)) if segundos: tiempo_acumulado=0 for t in lista_tiempos: notas=t.obtener_nota_obj() tiempo=t.obtener_tiempo() if tiempo_acumulado+tiempo<=segundos: a_reproducir.append((notas,tiempo)) tiempo_acumulado+=tiempo continue a_reproducir.append((notas,segundos-tiempo_acumulado)) break for nota,tiempo in a_reproducir: sp.play_sounds(nota,tiempo) sp.close()
def reproducir(self): sp = pysounds.SoundPlayer(8) a_reproducir = [] for t in self.tiempos: #me parece que esta implementacion va a tardar # Si tarda creamos una funcion que obtenga la nota y el tiempo antes notas = t.obtener_nota_obj() tiempo = t.obtener_tiempo() a_reproducir.append((notas, tiempo)) for nota, tiempo in a_reproducir: sp.play_sounds(nota, tiempo) sp.close()
def reproducir(self, tiempos_y_habilitados): """ Pre: recibe un lista de tuplas, donde cada una tiene un tiempo (numero), y una lista de tracks habilitados. Post: reproduce la cantidad recibida de marcas de tiempo (tuplas). """ reproductor_interno = soundPlayer.SoundPlayer(self.canales) tiempos_y_sonidos = [] for tiempo_y_habilitado in tiempos_y_habilitados: tiempo = tiempo_y_habilitado[0] sonidos = self.obtener_sonidos(tiempo_y_habilitado[1]) tiempos_y_sonidos.append((tiempo, sonidos)) for tiempo_y_sonido in tiempos_y_sonidos: tiempo, sonidos = tiempo_y_sonido reproductor_interno.play_sounds(sonidos, tiempo)
def reproducir(tiempos, cant_canales, contador_tiempos, contador, sonidos): sp = pysounds.SoundPlayer(int(cant_canales)) sonidos_final = [] print(tiempos) for x in range(0, contador): tipo, frecuencia, volumen = sonidos[x] sonidos_final.append( pysounds.SoundFactory.get_sine_sound(int(frecuencia), float(volumen))) for i in range(0, contador_tiempos, 2): tiempo = float(tiempos[i]) for sounds in tiempos[i + 1]: for var in sounds: sonorata = [] if var: sonorata.append(sonidos_final[sounds.index(var)]) sp.play_sounds(sonorata, tiempo)
def _reproducir(self, mark): """Reproduce una marca de tiempo""" sp = pysounds.SoundPlayer(self.cant_tracks()) duracion = mark.obtener_duracion() sonidos_a_reproducir = [] for track_numero in mark.obtener_habilitados(): track = self.tracks[track_numero] tipo = track.obtener_tipo() freq = track.obtener_frecuencia() vol = track.obtener_volumen() if tipo == "sine": sonidos_a_reproducir.append( pysounds.SoundFactory.get_sine_sound(freq, vol)) if tipo == "triangular": sonidos_a_reproducir.append( pysounds.SoundFactory.get_triangular_sound(freq, vol)) if tipo == "square": sonidos_a_reproducir.append( pysounds.SoundFactory.get_square_sound(freq, vol)) sp.play_sounds(sonidos_a_reproducir, duracion)
def playThis(self, posiciones): """ Recibe una lista de posiciones, y reproduce las marcas que se encuentran en las mismas. """ if self.tracks.len==0: return acordes=ListaEnlazada() tracks = ListaEnlazada() tiempos = ListaEnlazada() reproductor = pysounds.SoundPlayer(len(self.tracks)) for pos in posiciones: tiempo, notas=self.marks[pos] self.notasALista(tiempo, notas, acordes) try: for track,tiempo in acordes: reproductor.play_sounds(track,tiempo) except OSError: raise OSError("Ocurrió un problema en la reproducción.")
def reproducir_tiempos(self, lista_tiempos=False, segundos=False): sp = pysounds.SoundPlayer(8) a_reproducir = [] if not segundos: for t in lista_tiempos: notas = t.obtener_nota_obj() tiempo = t.obtener_tiempo() a_reproducir.append((notas, tiempo)) if segundos: tiempo_acumulado = 0 for t in lista_tiempos: notas = t.obtener_nota_obj() tiempo = t.obtener_tiempo() if tiempo_acumulado + tiempo <= segundos: a_reproducir.append((notas, tiempo)) tiempo_acumulado += tiempo continue a_reproducir.append((notas, segundos - tiempo_acumulado)) break for nota, tiempo in a_reproducir: sp.play_sounds(nota, tiempo) sp.close()
#!/usr/bin/python3 import soundPlayer as pysounds sp = pysounds.SoundPlayer(2) A = pysounds.SoundFactory.get_triangular_sound(440, 0.1) B = pysounds.SoundFactory.get_triangular_sound(493.88, 0.1) C = pysounds.SoundFactory.get_triangular_sound(523.25, 0.1) D = pysounds.SoundFactory.get_triangular_sound(587.33, 0.1) E = pysounds.SoundFactory.get_triangular_sound(659.25, 0.1) G = pysounds.SoundFactory.get_triangular_sound(783.99, 0.1) Gm = pysounds.SoundFactory.get_triangular_sound(392.00, 0.1) Em = pysounds.SoundFactory.get_triangular_sound(329.63, 0.1) tempo = 0.1 sp.play_sounds([E, B], 4 * tempo) sp.play_sounds([B, Gm], 2 * tempo) sp.play_sounds([A, C], 2 * tempo) sp.play_sounds([B, D], 2 * tempo) sp.play_sounds([E], 1 * tempo) sp.play_sounds([D], 1 * tempo) sp.play_sounds([C, A], 2 * tempo) sp.play_sounds([B, Gm], 2 * tempo) sp.play_sounds([A, Em], 4 * tempo) sp.play_sounds([A, Em], 2 * tempo) sp.play_sounds([A, C], 2 * tempo) sp.play_sounds([E, C], 4 * tempo) sp.play_sounds([B, D], 2 * tempo) sp.play_sounds([C, A], 2 * tempo) sp.play_sounds([B, Gm], 2 * tempo) sp.play_sounds([B, Em], 2 * tempo) sp.play_sounds([B, Gm], 2 * tempo)
def abrir_reproductor(self): self.reproductor=pysounds.SoundPlayer(int(self.canales))
# -- Initialization Sensors: # i2c lcd = LCDS.LCDScreen() # aio(2) light = LS.LightSensor() # aio(1) mic = SS.MicSound() # gpio d2 motion = MS.MotionSensor() # aio(0) vibration = PVS.PiezoVibration() # gpio d(6) touch = mraa.Gpio(6) touch.dir(mraa.DIR_IN) # gpio d(5) buzzer = SP.SoundPlayer() # gpio d(8) blueLight = mraa.Gpio(8) blueLight.dir(mraa.DIR_OUT) # gpio d(7) redLight = mraa.Gpio(7) redLight.dir(mraa.DIR_OUT) class State: stateTitle = 'Normal' state = 1 s = State()