display name of .wav-file on I2C-16x2-Display

A
AlexT posted May 8, 21:33:

Hello together,
Does anyone know how to display the name of the playing .wav-file on a 16x2-Display?
I implemented the code for using an 16x2 via i2C-Backpack David Hilowitz and everything works fine. It maybe sounds weird in the first place but I use this as backing track player and the filename is the trackname...

How can I call the filename of the playing .wav file in the samplerbox.py and display it with lcd_string() in the second line? It should only be displayed when the track is playing. Maybe display with note_on and clear with note_off.

thank you in advance

A
AlexM posted May 11, 02:26:

You could add a filename property to the Sound object which is populated during loading (LoadSamples()). When a new sample is triggered by Sound.play(), send self.filename to the display.

A
AlexM posted May 11, 04:24:

Got ahead of myself there - the Sound object already has the filename/filepath! >> https://github.com/josephernest/SamplerBox/blob/master/samplerbox.py#L129

We can add something to the play method like this:

def play(self, note):
    snd = PlayingSound(self, note)
    playingsounds.append(snd)
    fname_to_lcd = self.fname.rsplit('/', 1)[-1] # get the filename after last slash
    lcd_string(fname_to_lcd)
    return snd

https://github.com/josephernest/SamplerBox/blob/master/samplerbox.py#L143-L146

A
AlexT posted May 11, 16:53:

Thank you for your quick response, this looks promising. I will test it as soon as possible!

A
AlexT posted May 17, 22:34:

It works perfectly, just added the ', 2' in the lcd string for line 2. I also changed polyphony to 1, so there is no conflict if accidentally a second "note" is hit. (Don't know if this is even a problem...)

...

  (not published)
  I want to post as guest
 

Post