Beispiel #1
0
def test_metronome(server):
    def trig_func():
        print(server.getCurrentTime(), 'trig')

    inp = pyo.Input([0,1])
    inx = pyo.Mix(inp)
    #atd = pyo.AttackDetector(inx)
    #prn = pyo.Print(atd, 1, message='attack')
    #avg = pyo.Average(inx)
    #prn = pyo.Print(avg, 1, message='avg')
    #sig = pyo.Sig(0.5)
    bpm = pyo.Sig(value=120)
    #bpm_round = pyo.Round(bpm)
    #bpm2 = pyo.Clip(bpm2, 30, 360)
    tpb = 2.5 / (pyo.Clip(pyo.Round(bpm), 30, 360))
    met = pyo.Metro(time=tpb)
    met.play()
    print(server.getBufferSize())
    trg = pyo.TrigFunc(met, trig_func)

    #ti = pyo.Timer(met, met)
    #prn = pyo.Print(met, 1, message='met')
    #bpm = pyo.Round(60 / ti)
    #bpm2 = pyo.Clip(bpm, 30, 360)
    #pr2 = pyo.Print(pyo.Clip(pyo.Round(60 / ti), 30, 360), 0, message='bpm')
    
    def update_met():
        print('update met')
        #met.setTime(0.4)
        bpm.setValue(150)
        #met.stop()
        #met.play()
    ca = pyo.CallAfter(update_met, 10)

    return bpm, trg, ca
Beispiel #2
0
def test_beat3(server):
    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)

    gt = pyo.Gate(mix, -30, outputAmp=True)
    prn = pyo.Print(gt, 1, message='gt')
    return prn
Beispiel #3
0
def test_level_to_midi(server):
    def trig_func(obj):
        print('velocity', obj.stream.getValue())
        velo = int(obj.stream.getValue())
        server.ctlout(28, velo, 1)
        #print(obj, dir(obj))
        #print(obj.stream, dir(obj.stream))

    #mc = functools.partial(meter_callback, server)
    #def mcb(*args, **kwargs):
    #    print(args, kwargs)
    #server.setMeterCallable(mcb)
    inp = pyo.Input([0,1])
    inx = pyo.Mix(inp)
    flr = pyo.Follower(inx)
    scl = pyo.Scale(flr, outmax=31, exp=0.5)
    rnd = pyo.Round(scl)
    #rnds = pyo.Switch(rnd, outs=2)
    #prn = pyo.Print(rnd, 1, message='rnd')
    chg = pyo.Change(rnd)
    #pr2 = pyo.Print(chg, 1, message='chg')
    scl2 = pyo.Scale(rnd, inmax=31, outmin=0, outmax=127)
    rnd2 = pyo.Round(scl2)
    trg = pyo.TrigFunc(chg, trig_func, rnd2)

    return trg
Beispiel #4
0
 def __init__(self, dur=1, refreshRate=.02):
     self.dur = dur
     self.refreshRate = refreshRate
     self.table = pyo.SndTable()
     self.tableOG = pyo.SndTable()
     self.durOG = 1
     self.input = pyo.Input()
     self.tabFill = pyo.TableFill(self.input, self.table)
Beispiel #5
0
 def _start_recording(self):
     self.__rec = pyo.Record(pyo.Input(),
                             filename=self._filename,
                             chnls=2,
                             fileformat=0,
                             sampletype=1,
                             buffering=16)
     self._rec_start = clock.now()
Beispiel #6
0
    def __init__(self):
        self.server = pyo.Server(nchnls=1).boot()
        self.server.setAmp(0.3)

        self.inp = pyo.Input()
        self.extractor = Extractor(self.inp)
        self.chain = Chain(self.inp)
        self.player = ChainWaver(self.chain, self.extractor).out()
Beispiel #7
0
 def setInputChannels(self, value):
     if not isinstance(value, (list, tuple)):
         value = [value]
     if self._input_channels != value:
         self._input_channels = value
         if self._but_lp:
             inp = pyo.Input(self._input_channels)
             mix = pyo.Mix(inp)
             self._but_lp.setInput(mix)
Beispiel #8
0
def test_beat3a(server):
    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)

    ad = pyo.AttackDetector(mix, 0.005, 10, 3, -30, 0.1)
    ad.ctrl()
    tmr = pyo.Timer(ad, ad)
    prn = pyo.Print(tmr, 1, message='tmr')
    return ad, prn
Beispiel #9
0
 def play(self):
     if not self._but_lp:
         inp = pyo.Input(self._input_channels)
         mix = pyo.Mix(inp)
         self._but_lp = pyo.ButLP(mix, self._lpf)
     if not self._follower:
         self._follower = pyo.Follower2(self._but_lp,
                                        risetime=self._attack,
                                        falltime=self._release)
     if not self._peak_amp:
         self._peak_amp = pyo.PeakAmp(self._follower,
                                      self._peak_amp_callback)
Beispiel #10
0
def test_beat3b(server):
    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)

    flr1 = pyo.Follower2(mix, 0.005, 0.005)
    spl1 = pyo.AToDB(flr1)
    flr2 = pyo.Follower2(mix, 0.1, 0.1)
    spl2 = pyo.AToDB(flr2)
    diff = spl2 - spl1
    thr = pyo.Thresh(diff, 6)
    nxt = pyo.TrackHold(diff, thr, 1)
    tmr = pyo.Timer(thr, thr)
    prn = pyo.Print(tmr, 1, message='thr')

    return prn, nxt
Beispiel #11
0
def test_beat1a(server):
    # Based on http://damian.pecke.tt/beat-detection-on-the-arduino
    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)

    # 20 - 200hz Bandpass Filter
    #q = pyo.Sig(.1) # No idea what Q should be...
    bpf = pyo.ButBP(mix, 63.245, 9.1)
    ab = pyo.Abs(bpf)
    lpf = pyo.ButLP(ab, 10)
    bp2 = pyo.ButBP(lpf, 2.57, 9)
    
    #server.setCallback()
    sp = pyo.Spectrum(bp2)
    
    return bpf, sp, lpf, bp2
Beispiel #12
0
def test_table(server):
    def process(): 
        data = table.getTable()
        # "data" is a list of floats of length "buffer size". 

    # Register the "process" function to be called at the beginning 
    # of every processing loop. 
    server.setCallback(process) 

    # Create a table of length `buffer size`. 
    table = pyo.DataTable(size=server.getBufferSize()) 

    inp = pyo.Input([0,1])
    mix = pyo.Mix(inp)

    # Fill the table with the audio signal every processing loop. 
    tfl = pyo.TableFill(mix, table)

    return tfl
Beispiel #13
0
    def StartAudioInputMeter(self):
        input_meter = wx.FindWindowById(ID_INPUT_METER)
        if not input_meter:
            self.StopAudioInputMeter()
            return

        input_meter_ref = weakref.ref(input_meter)

        def peak_amp_func(*args):
            meter_data = [min(120, max(0, int(-120.0 if arg < 0.000001 else 20.0 * math.log10(arg)) + 90)) for arg in args]
            # meter_data = [min(120, max(0, int(pyo.rescale(arg, 0, 1, 0, 120)))) for arg in args]
            input_meter = input_meter_ref()
            if input_meter:
                input_meter.SetData(meter_data, 0, len(meter_data))

        aic = self.GetAudioInputChannels()
        chans = [n for n in range(8) if (aic & (2 ** n))]
        inp = pyo.Input(chans)
        mix = pyo.Mix(inp, 2)
        self._input_peak_amp = pyo.PeakAmp(mix, peak_amp_func)
Beispiel #14
0
 def refresh(self):
     self.dur = self.dur
     self.table = pyo.SndTable('blank.wav', stop=self.dur)
     self.input = pyo.Input()
     self.tabFill = pyo.TableFill(self.input, self.table)
import pyo  #importing the library
from pyo import Tone  #importing the low frequency filter
from pyo import Atone  #importing the high frequency filter

s = pyo.Server().boot()  #declaring the server variable
s.start()  #Starting the Pyo Server
i = pyo.Input()  #declaring the input
low_filter = Tone(i, freq=280, mul=1,
                  add=0)  #setting the lowest frequency to 280 Hz
high_filter = Atone(low_filter, freq=4000, mul=1,
                    add=0).out()  #setting the highest fre to 4000 Hz

#source: http://ajaxsoundstudio.com/pyodoc/api/classes/filters.html
Beispiel #16
0
import pyo
import pygame

s = pyo.Server(audio="portaudio", nchnls=1).boot()
s.start()
audioIn = pyo.Input(chnl=0)

done = False
pygame.init()
clock = pygame.time.Clock()
pygame.joystick.init()
joystick = pygame.joystick.Joystick(0)
joystick.init()

x_button = False
x_count = 0
a_button = False
a_count = 0
b_button = False
b_count = 0
y_button = False
y_count = 0
L_button = False
L_count = 0
R_button = False
R_count = 0

# Initialize Chorus Variables
delay = 0.5  # range 0-5
feedback = 0.5  # range 0-1
balance = 0.5  # range 0-1
Beispiel #17
0
def test_beat1(server):

    server.server_ms = 0
    last_ms = 0
    server.last_bpm = 0
    server.bpms = []
    server.last_avg = 0

    def trig_func():
        #ct = server.getCurrentTime()
        delta = server_ms - last_ms
        last_ms = server_ms
        
        #delta = ct - last_ct
        #bpm = 
        print(delta, 'trig')

    def time_callback(hours, minutes, seconds, milliseconds):
        #print(hours, minutes, seconds, milliseconds)
        server.server_ms = hours * 3600000 + minutes * 60000 + seconds * 1000 + milliseconds

    def process_callback():
        if ad.minthresh != thr.get():
            ad.minthresh = thr.get()
        #if server.last_avg != avg.get():
        #    print('avg', avg.get())
        #    server.last_avg = avg.get()
        return 
        #bpm = 120 / (tmr.get() or 0.001)
        #while bpm > 360:
        #    bpm /= 2
        #while bpm < 40:
        #    bpm *= 2
        #print('bpm?', bpm)
        data = table.getTable()
        if len(data):
            #data = [d for d in data if d]
            #print(len(data), sum(data), server.server_ms)
            bpm = len(data) * 60 / (sum(data) or 0.001)
            while bpm > 360:
                bpm /= 2
            while bpm < 40:
                bpm *= 2
            #server.bpms.append()
            bpm = int(bpm)
            if bpm != server.last_bpm:
                server.last_bpm = bpm
                print('bpm?', bpm)
        
        table.reset()
        #tfl.play()
            #print(ad.minthresh)

    server.setTimeCallable(time_callback)
    server.setCallback(process_callback)

    table = pyo.DataTable(size=32) 

    inp = pyo.Input([0, 1])
    mix = pyo.Mix(inp)
    
    flr = pyo.Follower2(mix, 0.5, 0.5)
    fla = pyo.Average(flr, server.getBufferSize())
    #flr.ctrl()
    spl = pyo.AToDB(flr)
    thr = spl - 6
    ad = pyo.AttackDetector(mix, 0.005, 1000, 12, -30, 0.05)
    #ad.ctrl()
    #prn = pyo.Print(ad, 1, message='ad')
    prn = None
    tmr = pyo.Timer(ad, ad)
    #avg = pyo.Average(tmr, server.getBufferSize())
    #bpm = 60 / pyo.Min(tmr, 0.001)
    #trg = pyo.TrigFunc(ad, trig_func)
    prn2 = pyo.Print(tmr, 1, message='tmr')
    #tfl = pyo.TableFill(tmr, table)
    return ad, prn, thr, prn2
Beispiel #18
0
import pyo
from settings import audioSource

s = pyo.Server(audio=audioSource, nchnls=1).boot()
s.start()

a = pyo.Input(chnl=0)
chorus = pyo.Chorus(a, depth=.9, feedback=0.5, bal=0.5).out()

s.gui()
import subprocess

# # https://github.com/belangeo/pyo/blob/master/pyo/lib/server.py
# pyo.pa_list_devices() # list all audio devices
# sys.exit()

s = pyo.Server()
s.setInputDevice(4)
s.setOutputDevice(4)
s.boot()
s.start()

time.sleep(1)  # make sure server is booted

# print('s.getNchnls() = %s' % s.getNchnls())
a1 = pyo.Input()
p1 = pyo.Pan(a1).out()
# d1 = pyo.Disto(p1, drive=0.15).out()

# a2 = pyo.Input(chnl=0)
# p2 = pyo.Pan(a2).out(chnl=1)

# s2 = pyo.Server()
# s2.setInputDevice(0)
# s2.setOutputDevice(4)
# s2.boot()
# s2.start()
# a2 = pyo.Input()
# p2 = pyo.Pan(a2).out()
# # print(s1.getStreams())
Beispiel #20
0
    import midi

    # making final mixer
    MIXER = pyo.Mixer(outs=8, chnls=1)

    logging.info("getting inputs")
    if SIMULATION_VERSE:
        VERSE_PATH = "{}/{}".format(settings.SIMULATION_PATH, SIMULATION_VERSE)
        INPUTS = {
            instrument: pyo.SfPlayer(
                "{}/{}/synthesis.wav".format(VERSE_PATH, instrument), mul=0.7,
            )
            for instrument, _ in settings.INPUT2INSTRUMENT_MAPPING.items()
            if instrument != "pianoteq"
        }
        INPUTS.update({"pianoteq": pyo.Input(3)})

    else:
        INPUTS = {
            instrument: pyo.Input(channel).play()
            for instrument, channel in settings.INPUT2INSTRUMENT_MAPPING.items()
        }

    logging.info("adding meter for inputs")
    INPUT_METER = loclog.Meter(*INPUTS.items())

    logging.info("sending pianoteq to mixer")
    MIXER.addInput(settings.TRACK2MIXER_NUMBER_MAPPING["pianoteq"], INPUTS["pianoteq"])
    MIXER.setAmp(
        settings.TRACK2MIXER_NUMBER_MAPPING["pianoteq"],
        settings.PHYSICAL_OUTPUT2CHANNEL_MAPPING["pianoteq"],
Beispiel #21
0
import pyo
from settings import audioSource

s = pyo.Server(audio=audioSource, nchnls=1).boot()
s.start()

a = pyo.Input(chnl=0).out()

delay = pyo.Delay(a, delay=.5, feedback=.5)
delay.out()

while True:
    s = raw_input('Delay');
    if s == "q":
        quit()
    delay.setDelay(float(s))

#s.gui(locals())
Beispiel #22
0
 def __init__(self):
     super().__init__()
     self.son = pyo.Input(1)
     self.synth = pyo.Harmonizer(self.son, 1)
     self.filter = pyo.Biquad(self.synth)
     self.verb = pyo.WGVerb(self.filter).mix(2)
Beispiel #23
0
def main():
    '''Main method. Inits gpio, bridge, jack, and pyo. Then reads effects and starts handling gpio'''
    # If GPIO is enabled, initialize the pins and GPIO module.
    if GPIO_CAPABLE:
        GPIO.setmode(GPIO.BCM)
        GPIO.setwarnings(False)
        GPIO.setup(button_pin, GPIO.IN, GPIO.PUD_UP)
        GPIO.setup(23, GPIO.OUT)

        gpio_controller = gpiocontrol.GpioController()

    # Initialize the bridge to allow the app to accept connections.
    bridge_conn = bridge.Bridge()

    # Set up custom options for the sockets
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) #UDP SOCKET
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #TCP SOCKET
    s.setblocking(0)
    sock.setblocking(0)
    s.bind(('', 10000))
    sock.bind(('', 10001))

    jack_id = jackserver.start_jack_server()

    # give the application time for JACK to boot.
    time.sleep(5)

    # JACK and Pyo set up procedures
    pyo_server = start_pyo_server()
    pyo_server.setJackAuto()

    # Read input from the audio device on channel 0
    # and apply the necessary effects from the config file 
    enabled_effects = chain_effects(pyo.Input(chnl=0), configparser.get_effects())
    apply_effects( enabled_effects )

    # Create necessary variables used by the GPIO controller module
    record_table = []
    audio_recorder = []
    loop = []
    record_table.append(pyo.NewTable(length=60, chnls=1, feedback=0.5))
    audio_recorder.append(pyo.TableRec((enabled_effects[len(enabled_effects) - 1]), table=record_table[-1], fadetime=0.05))
    already_recording = False
    recording_time = 0
    inactive_end_time = 0
    signal.signal(signal.SIGINT, partial(signal_handler, jack_id, pyo_server))

    while True:
        # Executes GPIO and loop machine logic flow.
        if GPIO_CAPABLE:
            # Read the state of the button press. 
            BUTTON_STATE = gpio_controller.update_gpio()
            # Perform actions dependent on the state of the button press.
            if BUTTON_STATE == 'INACTIVE' or BUTTON_STATE == 'LOOPING':
                inactive_end_time = time.time()
            if BUTTON_STATE == 'RECORDING':
                recording_time = time.time()
                if not already_recording:
                    print("Recording audios for 5 segundos")
                    (audio_recorder[-1]).play()
                    already_recording = True
            elif BUTTON_STATE == 'ACTIVATE_LOOP':
                loop_len = recording_time - inactive_end_time
                loop.append(
                    pyo.Looper(
                        table=record_table[-1],
                        dur=loop_len, xfade=0,
                        mul=1).out()
                    )
                record_table.append(
                    pyo.NewTable(
                        length=60,
                        chnls=1,
                        feedback=0.5)
                    )
                audio_recorder.append(
                    pyo.TableRec(
                        (enabled_effects[len(enabled_effects) - 1]),
                        table=record_table[-1],
                        fadetime=0.05)
                    )
                print("ACTIVATING LOOP")
                gpio_controller.set_state("LOOPING")
                already_recording = False
            elif BUTTON_STATE == 'CLEAR_LOOP':
                loop = []
                record_table = []
                audio_recorder = []
                record_table.append(
                    pyo.NewTable(
                        length=60,
                        chnls=1,
                        feedback=0.5)
                    )
                audio_recorder.append(
                    pyo.TableRec(
                        (enabled_effects[len(enabled_effects) - 1]),
                        table=record_table[-1],
                        fadetime=0.05)
                    )
                gpio_controller.set_state("INACTIVE")

        # See if we got a message from the frontend application
        res = bridge_conn.backend(s,sock)
        if res:
            print(res)
            if 'UPDATEPORT' == res[0]:
                # There was a request to update the ports. Kill the
                # JACK server and restart it with the new ports.
                print("Request to update ports")
                pyo_server.shutdown()
                jackserver.kill_jack_server(jack_id)
                time.sleep(2)
                jack_id = jackserver.start_jack_server(jackserver.filter_port_selection(res[1]), jackserver.filter_port_selection(res[2]))
                time.sleep(2)
                pyo_server.reinit(**PYO_INIT_SETTINGS)
                pyo_server.boot()
                pyo_server.start()
            enabled_effects[-1].stop()
            enabled_effects = chain_effects(pyo.Input(chnl=0), configparser.get_effects())
            apply_effects( enabled_effects )
        time.sleep(0.0001)
Beispiel #24
0
 def create_synth_passthrough(self):
     '''Create a "synth" that will pass audio on the input channel to 
     your output channel(s).'''
     self.log.debug('creating passthrough synth')
     i = pyo.Input()
     return pyo.Mix(i, voices=2, mul=0)