Ejemplo n.º 1
0
def Button_display():
    global buttfunc, button_functions
    function_value = [
        "",
        " %d%%" % (gv.volume),
        " %d" % (gv.MIDI_CHANNEL), "",
        " %s" % (gv.chordname[gv.currchord]),
        " %s" % (gv.scalename[gv.currscale])
    ]
    gv.display(button_functions[buttfunc] + function_value[buttfunc])
Ejemplo n.º 2
0
            amix = alsaaudio.Mixer(cardindex=gv.MIXER_CARD_ID+i,control=MIXER_CONTROL[j])
            gv.MIXER_CARD_ID+=i    # save the found value
            ok=True             # indicate OK
            print 'Opened Alsamixer: card (hw:%i,x), control %s' % (gv.MIXER_CARD_ID, MIXER_CONTROL[j])
            break
        except:
            pass
    if ok: break

if ok:
    def getvolume():
        vol = amix.getvolume()
        gv.volume = int(vol[0])
    def setvolume(volume):
        amix.setvolume(volume)
        getvolume()
    setvolume(gv.volume)
else:
    gv.USE_ALSA_MIXER=False
    gv.display("Invalid mixerdev")
    print 'Invalid mixer card id "%i" or control "%s" --' % (gv.MIXER_CARD_ID, MIXER_CONTROL)
    print '-- Mixer card id is "x" in "(hw:x,y)" (if present) in opened audio device.'

if not gv.USE_ALSA_MIXER:
    def getvolume():
        pass
    def setvolume(volume):
        pass

gv.setvolume=setvolume              # and announce the procs to modules
Ejemplo n.º 3
0
            if d['max_output_channels'] > 0:
                if 'bcm2835' in d['name']:
                    if not device_found:  # keep the first PI sound device as a bypass
                        device_found = True
                        AUDIO_DEVICE_ID = i
                        AUDIO_DEVICE_NAME = d['name']
                elif 'default' not in d['name'] and 'dmix' not in d['name']:
                    AUDIO_DEVICE_ID = i
                    AUDIO_DEVICE_NAME = d['name']
                    break  # found a valid non-builtin device
            i += 1
        if 'bcm2835' in AUDIO_DEVICE_NAME:
            BLOCKSIZE = "high"  # force the PI sound device to sound OK
        OpenDevice(f)
except:
    gv.display("Invalid audiodev")
    print('Invalid audio device #%i %s' % (AUDIO_DEVICE_ID, AUDIO_DEVICE_NAME))
    try:
        print('Available audio devices')
        print(sounddevice.query_devices())
    except:
        print('** sounddevice returns error! **')
    time.sleep(0.5)
    gv.GPIOcleanup()
    exit(1)

device_found = False
if mixer_control.title() != "None":
    import alsaaudio
    mixer_card_index = re.search(
        '\(hw:(.*),', AUDIO_DEVICE_NAME)  # get x from (hw:x,y) in device name
Ejemplo n.º 4
0
    def do_POST(self):
        inval = 0

        length = int(self.headers.getheader('content-length'))
        field_data = self.rfile.read(length)
        fields = parse_qs(field_data)
        #print fields
        if "SB_RenewMedia" in fields:
            if fields["SB_RenewMedia"][0] == "Yes":
                gv.basename = "None"
                self.LoadSamples()
                return
        if "SB_Preset" in fields:
            inval = gv.presetlist[int(fields["SB_Preset"][0])][0]
            if gv.PRESET != inval:
                gv.PRESET = inval
                self.LoadSamples()
                return
        if "SB_DefinitionTxt" in fields:
            if gv.DefinitionTxt != fields["SB_DefinitionTxt"][0]:
                gv.DefinitionTxt = fields["SB_DefinitionTxt"][0]
                #print gv.DefinitionTxt
                subprocess.call(['mount', '-vo', 'remount,rw', gv.samplesdir])
                fname = gv.samplesdir + gv.presetlist[gv.getindex(
                    gv.PRESET, gv.presetlist)][1] + "/" + gv.SAMPLESDEF
                with open(fname, 'w') as definitionfile:
                    definitionfile.write(gv.DefinitionTxt)
                subprocess.call(['mount', '-vo', 'remount,ro', gv.samplesdir])
                gv.basename = "None"  # do a renew to sync the update
                self.LoadSamples()
                return
        if "SB_MidiChannel" in fields:
            gv.MIDI_CHANNEL = int(fields["SB_MidiChannel"][0])
        if "SB_SoundVolume" in fields:
            gv.setvolume(int(fields["SB_SoundVolume"][0]))
        if "SB_MidiVolume" in fields:
            gv.volumeCC = float(fields["SB_MidiVolume"][0]) / 100
        if "SB_Gain" in fields:
            gv.globalgain = float(fields["SB_Gain"][0]) / 100
        if "SB_Pitchrange" in fields:
            gv.pitchnotes = int(fields["SB_Pitchrange"][0]) * 2
        if "SB_Voice" in fields:
            if gv.voicelist[0][0] == 0: i = 1
            else: i = 0
            gv.MC[gv.getindex(gv.VOICES,
                              gv.MC)][2](int(fields["SB_Voice"][0]) + i, 0)
        if "SB_Notemap" in fields:
            gv.MC[gv.getindex(gv.NOTEMAPS,
                              gv.MC)][2](int(fields["SB_Notemap"][0]))
        if "SB_Scale" in fields:
            inval = int(fields["SB_Scale"][0])
            if gv.currscale == inval: scalechange = False
            else:
                scalechange = True
                gv.currscale = inval
                if gv.last_musicnote < 0: gv.currchord = 0
                else:
                    gv.currchord = gv.scalechord[gv.currscale][
                        gv.last_musicnote]
        if "SB_Chord" in fields and not scalechange:
            inval = int(fields["SB_Chord"][0])
            if not gv.currchord == inval:
                gv.currchord = inval
                gv.currscale = 0
        if "SB_CHOrus" in fields:
            CHOrus.setType(
                gv.getindex(fields["SB_CHOrus"][0], ["Off", "On"], True))
        if "SB_CHOdepth" in fields:
            CHOrus.setdepth((float(fields["SB_CHOdepth"][0]) - 2) * 9.77)
        if "SB_CHOgain" in fields:
            CHOrus.setgain((float(fields["SB_CHOgain"][0]) - 30) * 2.54)
        if "SB_FVtype" in fields:
            Cpp.FVsetType(
                gv.getindex(fields["SB_FVtype"][0], ["Off", "On"], True))
        if "SB_FVroomsize" in fields:
            Cpp.FVsetroomsize(float(fields["SB_FVroomsize"][0]) * 1.27)
        if "SB_FVdamp" in fields:
            Cpp.FVsetdamp(float(fields["SB_FVdamp"][0]) * 1.27)
        if "SB_FVlevel" in fields:
            Cpp.FVsetlevel(float(fields["SB_FVlevel"][0]) * 1.27)
        if "SB_FVwidth" in fields:
            Cpp.FVsetwidth(float(fields["SB_FVwidth"][0]) * 1.27)
        if "SB_AWtype" in fields:
            Cpp.AWsetType(gv.getindex(fields["SB_AWtype"][0], gv.AWtypes,
                                      True))
        if "SB_AWmixing" in fields:
            Cpp.AWsetMixing(float(fields["SB_AWmixing"][0]) * 1.27)
        if "SB_AWattack" in fields:
            Cpp.AWsetAttack(float(fields["SB_AWattack"][0]) * 0.254)
        if "SB_AWrelease" in fields:
            Cpp.AWsetRelease(float(fields["SB_AWrelease"][0]) * 0.254)
        if "SB_AWminfreq" in fields:
            Cpp.AWsetMinFreq(float(fields["SB_AWminfreq"][0]) * 0.254)
        if "SB_AWmaxfreq" in fields:
            Cpp.AWsetMaxFreq(float(fields["SB_AWmaxfreq"][0]) * 0.0127)
        if "SB_AWqfactor" in fields:
            Cpp.AWsetQualityFactor(float(fields["SB_AWqfactor"][0]) * 0.0508)
        if "SB_AWspeed" in fields:
            Cpp.AWsetSpeed((float(fields["SB_AWspeed"][0]) - 100) * 0.127)
        if "SB_AWlvlrange" in fields:
            Cpp.AWsetLVLrange(float(fields["SB_AWlvlrange"][0]) * 1.27)
        if "SB_DLYtype" in fields:
            Cpp.DLYsetType(
                gv.getindex(fields["SB_DLYtype"][0], gv.DLYtypes, True))
        if "SB_DLYfb" in fields:
            Cpp.DLYsetfb(float(fields["SB_DLYfb"][0]) * 1.27)
        if "SB_DLYwet" in fields:
            Cpp.DLYsetwet(float(fields["SB_DLYwet"][0]) * 1.27)
        if "SB_DLYdry" in fields:
            Cpp.DLYsetdry(float(fields["SB_DLYdry"][0]) * 1.27)
        if "SB_DLYtime" in fields:
            Cpp.DLYsettime(
                (float(fields["SB_DLYtime"][0]) - 1000) / 600 * 1.27)
        if "SB_DLYsteep" in fields:
            Cpp.DLYsetsteep((float(fields["SB_DLYsteep"][0]) - 1) * 12.7)
        if "SB_DLYsteplen" in fields:
            Cpp.DLYsetsteplen(
                (float(fields["SB_DLYsteplen"][0]) - 300) / 30 * 1.27)
        if "SB_DLYmin" in fields:
            Cpp.DLYsetmin((float(fields["SB_DLYmin"][0]) - 5) * 5.36)
        if "SB_DLYmax" in fields:
            Cpp.DLYsetmax((float(fields["SB_DLYmax"][0]) - 50) * 1.27)
        if "SB_LFtype" in fields:
            Cpp.LFsetType(
                gv.getindex(fields["SB_LFtype"][0], ["Off", "On"], True))
        if "SB_LFresonance" in fields:
            Cpp.LFsetResonance(float(fields["SB_LFresonance"][0]) / 38 * 127)
        if "SB_LFcutoff" in fields:
            Cpp.LFsetCutoff(
                (float(fields["SB_LFcutoff"][0]) - 1000) / 100 * 1.27)
        if "SB_LFdrive" in fields:
            Cpp.LFsetDrive(
                (float(fields["SB_LFdrive"][0]) - 1) * 6.35)  # =/20.0*127)
        if "SB_LFlvl" in fields:
            Cpp.LFsetLvl((float(fields["SB_LFlvl"][0])) * 1.27)
        if "SB_LFgain" in fields:
            Cpp.LFsetGain((float(fields["SB_LFgain"][0]) - 10) * 1.27)
        if "SB_LFOtype" in fields:
            LFO.setType(gv.getindex(fields["SB_LFOtype"][0], gv.LFOtypes,
                                    True))
        if "SB_VIBRpitch" in fields:
            gv.VIBRpitch = float(fields["SB_VIBRpitch"][0]) / 16
        if "SB_VIBRspeed" in fields:
            LFO.VibrSetspeed(int(fields["SB_VIBRspeed"][0]) * 4)
        if "SB_VIBRtrill" in fields:
            if fields["SB_VIBRtrill"][0].title() == "On": gv.VIBRtrill = True
            else: gv.VIBRtrill = False
        if "SB_TREMampl" in fields:
            gv.TREMampl = float(fields["SB_TREMampl"][0]) / 100
        if "SB_TREMspeed" in fields:
            LFO.TremSetspeed(int(fields["SB_TREMspeed"][0]) * 4)
        if "SB_TREMtrill" in fields:
            if fields["SB_TREMtrill"][0].title() == "On": gv.TREMtrill = True
            else: gv.TREMtrill = False
        if "SB_PANwidth" in fields:
            gv.PANwidth = float(fields["SB_PANwidth"][0]) / 20
        if "SB_PANspeed" in fields:
            LFO.PanSetspeed(int(fields["SB_PANspeed"][0]) * 4)
        if "SB_ARPord" in fields:
            arp.ordnum(gv.getindex(fields["SB_ARPord"][0], gv.ARPtypes, True))
        if "SB_ARPstep" in fields:
            arp.tempo(int(fields["SB_ARPstep"][0]) * 1.27)
        if "SB_ARPsustain" in fields:
            arp.sustain(int(fields["SB_ARPsustain"][0]) * 1.27)
        if "SB_ARPloop" in fields:
            if fields["SB_ARPloop"][0].title() == "On": arp.loop = True
            else: arp.loop = False
        if "SB_ARP2end" in fields:
            if fields["SB_ARP2end"][0].title() == "On": arp.play2end = True
            else: arp.play2end = False
        if "SB_ARPfade" in fields:
            arp.fadeout(1.27 * int(fields["SB_ARPfade"][0]))
        gv.display("")  # show it on the box
        self.do_GET()  # as well as on the gui
Ejemplo n.º 5
0
def Buttons():
    global lastbuttontime, buttfunc, button_functions, BUT_incr, BUT_decr, BUT_sel, button_disp

    GPIO.setmode(GPIO.BCM)
    GPIO.setup(BUT_incr, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(BUT_decr, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    GPIO.setup(BUT_sel, GPIO.IN, pull_up_down=GPIO.PUD_UP)
    lastbuttontime = time.time()
    print 'Started buttons via GPIO: Increment=%d, Decrement=%d, Select=%d' % (
        BUT_incr, BUT_decr, BUT_sel)

    while True:
        now = time.time()
        if (now - lastbuttontime) > 0.2:
            if not GPIO.input(BUT_decr):
                lastbuttontime = now
                if buttfunc == 0:
                    x = gv.getindex(gv.PRESET, gv.presetlist) - 1
                    if x < 0: x = len(gv.presetlist) - 1
                    gv.PRESET = gv.presetlist[x][0]
                    gv.LoadSamples()
                elif buttfunc == 1:
                    gv.volume -= 5
                    if gv.volume < 0: gv.volume = 0
                    gv.setvolume(gv.volume)
                    Button_display()
                elif buttfunc == 2:
                    gv.MIDI_CHANNEL -= 1
                    if gv.MIDI_CHANNEL < 1: gv.MIDI_CHANNEL = 16
                    Button_display()
                elif buttfunc == 3:
                    if not gv.midi_mute:
                        gv.midi_mute = True
                        gv.display("** MIDI muted **")
                    else:
                        gv.midi_mute = False
                        Button_display()
                elif buttfunc == 4:
                    gv.currscale = 0  # scale and chord mode are mutually exclusive
                    gv.currchord -= 1
                    if gv.currchord < 0: gv.currchord = len(gv.chordname) - 1
                    Button_display()
                elif buttfunc == 5:
                    gv.currchord = 0  # scale and chord mode are mutually exclusive
                    gv.currscale -= 1
                    if gv.currscale < 0: gv.currscale = len(gv.scalename) - 1
                    Button_display()

            elif not GPIO.input(BUT_incr):
                lastbuttontime = now
                gv.midi_mute = False
                if buttfunc == 0:
                    x = gv.getindex(gv.PRESET, gv.presetlist) + 1
                    if x >= len(gv.presetlist): x = 0
                    gv.PRESET = gv.presetlist[x][0]
                    gv.LoadSamples()
                elif buttfunc == 1:
                    gv.volume += 5
                    if gv.volume > 100: gv.volume = 100
                    gv.setvolume(gv.volume)
                    Button_display()
                elif buttfunc == 2:
                    gv.MIDI_CHANNEL += 1
                    if gv.MIDI_CHANNEL > 16: gv.MIDI_CHANNEL = 1
                    Button_display()
                elif buttfunc == 3:
                    gv.basename = "None"
                    gv.LoadSamples()
                    #Button_display()   # loadsamples also displays
                elif buttfunc == 4:
                    gv.currscale = 0  # scale and chord mode areLoadSamples mutually exclusive
                    gv.currchord += 1
                    if gv.currchord >= len(gv.chordname): gv.currchord = 0
                    Button_display()
                elif buttfunc == 5:
                    gv.churrchord = 0  # scale and chord mode are mutually exclusive
                    gv.currscale += 1
                    if gv.currscale >= len(gv.scalename): gv.currscale = 0
                    Button_display()

            elif not GPIO.input(BUT_sel):
                lastbuttontime = now
                buttfuncmax = len(button_functions)
                buttfunc += 1
                if buttfunc >= len(button_functions): buttfunc = 0
                if not gv.USE_ALSA_MIXER:
                    if button_disp[buttfunc] == "V": buttfunc += 1
                #use if above gets complex: if buttfunc >= len(button_functions): buttfunc=0
                gv.midi_mute = False
                Button_display()

            time.sleep(0.02)