josephernest / SamplerBox

SamplerBox is a sampler musical instrument based on RaspberryPi.
https://www.samplerbox.org
422 stars 97 forks source link

Volume control with piano fader #26

Closed corentoulf closed 7 years ago

corentoulf commented 7 years ago

Hello, I was trying to add a volume control from a fader on my piano. Looking at your code, I'm trying to set the globalvolume variable with this peace of code (that I placed in the "audio and midi callbacks" section) :

elif (messagetype == 11) and (note == 7):  # Ctrl change
    vol = velocity * 0.3545 - 48
    globalvolume = 10 ** ( vol / 20)
    print vol

Unfortunately, I can see that my fader acts but nothing changes on the audio volume. Could you guide me in handling this ?

Thank you !

corentoulf commented 7 years ago

For those looking for volume control, I got it working like this :

In the "import modules" part, add this :

from subprocess import call

In the audio and midi callbacks, add something like this :

elif (messagetype == 11) and (note == 7):  # Ctrl change
        vol = int(0.7402*velocity) # scales 0-->127 to 0-->100
        call(["amixer", "-c", "0", "set", "HPOUT2 Digital", str(vol)+"%"]) # shell command to set the card n°0 to "volume" in %
        print velocity
        print vol

Replace the note number by the fader number you want to use, the card number by the one you use and you're set !