Exemple #1
0
    def setupCtl(self, gen):
        param_manager = ParamManager(self.ns)

        midi_readers = None
        if hasattr(gen, 'midi'):
            mappings = None
            if hasattr(gen, 'mappings'):
                mappings = gen.mappings

            midi_readers = midi.get_midi_readers(gen.midi, mappings, self.ns)

        group = None
        if hasattr(gen, 'groups'):
            group = gen.groups[ voice_index % len(gen.groups) ]

        if hasattr(gen, 'samples'):
            samples = {}
            for snd in gen.samples:
                samples[snd[0]] = dsp.read(snd[1]).data
        else:
            samples = None

        ctl = {
            'param': param_manager,
            'midi': midi_readers,
            'group': group, 
            'samples': samples,
            'note': None # for armed voices, this will be populated with note/velocity info
        }

        return ctl
Exemple #2
0
    def setupCtl(self, gen, voice_index=0):
        param_manager = ParamManager(self.ns)
        osc_manager = osc.OscManager(self.ns)

        midi_readers = None
        if hasattr(gen, 'midi'):
            mappings = None
            if hasattr(gen, 'mappings'):
                mappings = gen.mappings

            midi_readers = midi.get_midi_readers(gen.midi, mappings, self.ns)

        if hasattr(gen, 'samples'):
            samples = {}
            for snd in gen.samples:
                samples[snd[0]] = dsp.read(snd[1]).data
        else:
            samples = None

        ctl = {
            'param': param_manager,
            'osc': osc_manager,
            'midi': midi_readers,
            'samples': samples,
            'note': (
                None, None
            )  # for armed voices, this will be populated with note/velocity info
        }

        return ctl
Exemple #3
0
    def setupCtl(self, gen, voice_index=0):
        param_manager = ParamManager(self.ns)
        osc_manager   = osc.OscManager(self.ns)

        midi_readers = None
        if hasattr(gen, 'midi'):
            mappings = None
            if hasattr(gen, 'mappings'):
                mappings = gen.mappings

            midi_readers = midi.get_midi_readers(gen.midi, mappings, self.ns)

        if hasattr(gen, 'samples'):
            samples = {}
            for snd in gen.samples:
                samples[snd[0]] = dsp.read(snd[1]).data
        else:
            samples = None

        ctl = {
            'param': param_manager,
            'osc': osc_manager,
            'midi': midi_readers,
            'samples': samples,
            'note': (None, None) # for armed voices, this will be populated with note/velocity info
        }

        return ctl
Exemple #4
0
    def play(self, generator, ns, voice_id, voice_index, loop=True):
        sys.path.insert(0, os.getcwd())
        gen = __import__(generator)

        midi_devices = {}

        if hasattr(gen, 'midi'):
            for device, device_id in gen.midi.iteritems():
                dsp.log('\ndevice: %s device_id: %s' % (device, device_id))

                try:
                    pygame.midi.init()
                    device_info = pygame.midi.get_device_info(device_id)
                    device_type = 'input' if device_info[2] else 'output'
                    pygame.midi.quit()
                except:
                    dsp.log('could not read device %s' % device_id)
                    device_type = 'output'

                try:
                    mappings = None
                    if hasattr(gen, 'mappings'):
                        if device in gen.mappings:
                            mappings = gen.mappings[device]

                    midi_devices[device] = MidiManager(device_id, ns, device_type, mappings)
                    dsp.log('setting midi manager %s' % device_id)
                except:
                    dsp.log('Could not load midi device %s with id %s' % (device, device_id))

        param_manager = ParamManager(ns)

        if audio_engine == 'alsa':
            out = self.open_alsa_pcm(ns.device)
        elif audio_engine == 'portaudio':
            out = self.open_pyaudio_pcm(ns.device)
        else:
            print 'Playback is disabled.'
            return False

        try:
            os.nice(-2)
        except OSError:
            os.nice(0)

        group = None
        if hasattr(gen, 'groups'):
            group = gen.groups[ voice_index % len(gen.groups) ]

        if hasattr(gen, 'sbank'):
            sbank = {}
            for snd in gen.sbank:
                sbank[snd[0]] = dsp.read(snd[1]).data
        else:
            sbank = None

        meta = {
            'midi': midi_devices,
            'param': param_manager,
            'id': voice_id,
            'group': group, 
            'sbank': sbank
        }

        if not hasattr(ns, 'reload'):
            setattr(ns, 'reload', False)

        render_process = None

        def render_again(gen, meta, voice_id, ns):
            snd = gen.play(meta)
            setattr(ns, 'buffer-%s' % voice_id, snd)

        iterations = 0
        while getattr(ns, '%s-%s-loop' % (generator, voice_id)) == True:
            meta['iterations'] = iterations
            iterations += 1

            dsp.log('playing %s, id %s, iter %s' % (generator, voice_id, iterations))

            if getattr(ns, 'reload') == True and not hasattr(gen, 'automate'):
                reload(gen)

            # automate will always override play
            if hasattr(gen, 'play') and not hasattr(gen, 'automate'):
                if hasattr(ns, 'buffer-%s' % voice_id):
                    snd = getattr(ns, 'buffer-%s' % voice_id)
                else:
                    # First play render
                    snd = gen.play(meta)

                if render_process is None or not render_process.is_alive():
                    # async start render of next buffer
                    render_process = mp.Process(name='render-%s' % voice_id, target=render_again, args=(gen, meta, voice_id, ns))
                    render_process.start()

                snd = dsp.split(snd, 500)

                # if grid is on, wait for a tick to start playback
                if ns.grid:
                    self.tick.wait()

                for s in snd:
                    try:
                        out.write(s)
                    except AttributeError:
                        dsp.log('Could not write to audio device')
                        return False

            if hasattr(gen, 'automate'):
                gen.automate(meta)

                if hasattr(gen, 'loop_time'):
                    time.sleep(gen.loop_time)

        delattr(ns, 'buffer-%s' % voice_id)

        return True
Exemple #5
0
def play(args):
    snd = False
    reps = 8
    length = dsp.stf(20)
    volume = 0.1 
    octave = 4 
    note = 'd'
    quality = tune.major
    m = 1
    width = 0
    waveform = 'sine'

    scale = [1,5,8]
    wtypes = ['sine', 'phasor', 'line', 'saw']

    for arg in args:
        a = arg.split(':')

        if a[0] == 't':
            length = int(a[1])

        if a[0] == 'v':
            volume = float(a[1]) / 100.0

        if a[0] == 'r':
            reps = int(a[1])

        if a[0] == 'n':
            note = a[1]

        if a[0] == 'm':
            m = float(a[1])

        if a[0] == 'w':
            width = dsp.mstf(float(a[1]))

        if a[0] == 'q':
            if a[1] == 'M':
                quality = tune.major
            elif a[1] == 'm':
                quality = tune.minor
            else:
                quality = tune.major

        if a[0] == 'g':
            glitch = True

        if a[0] == 's':
            if a[1] == 'c':
                snd = dsp.read('sounds/clapshake.wav').data
            elif a[1] == 'h':
                snd = dsp.read('sounds/hihat.wav').data
            elif a[1] == 's':
                snd = dsp.read('sounds/snare.wav').data
            elif a[1] == 'k':
                snd = dsp.read('sounds/kick.wav').data
            else:
                snd = dsp.read('sounds/hihat.wav').data


    out = ''

    if(w <= 11):
        w = 11

    width = dsp.mstf(t)
    for h in range(reps):
        s = dsp.cut(snd, dsp.randint(0, 100), w)
        out += dsp.pad(s, 0, width - dsp.flen(s))
    
    out = dsp.env(out, 'gauss')

    return dsp.cache(dsp.amp(out, volume))
Exemple #6
0
    def play(self, generator, ns, voice_id, voice_index, loop=True):
        sys.path.insert(0, os.getcwd())
        gen = __import__(generator)

        midi_devices = {}

        if hasattr(gen, 'midi'):
            for device, device_id in gen.midi.iteritems():
                dsp.log('\ndevice: %s device_id: %s' % (device, device_id))

                try:
                    pygame.midi.init()
                    device_info = pygame.midi.get_device_info(device_id)
                    device_type = 'input' if device_info[2] else 'output'
                    pygame.midi.quit()
                except:
                    dsp.log('could not read device %s' % device_id)
                    device_type = 'output'

                try:
                    mappings = None
                    if hasattr(gen, 'mappings'):
                        if device in gen.mappings:
                            mappings = gen.mappings[device]

                    midi_devices[device] = MidiManager(device_id, ns,
                                                       device_type, mappings)
                    dsp.log('setting midi manager %s' % device_id)
                except:
                    dsp.log('Could not load midi device %s with id %s' %
                            (device, device_id))

        param_manager = ParamManager(ns)

        if audio_engine == 'alsa':
            out = self.open_alsa_pcm(ns.device)
        elif audio_engine == 'portaudio':
            out = self.open_pyaudio_pcm(ns.device)
        else:
            print 'Playback is disabled.'
            return False

        try:
            os.nice(-2)
        except OSError:
            os.nice(0)

        group = None
        if hasattr(gen, 'groups'):
            group = gen.groups[voice_index % len(gen.groups)]

        if hasattr(gen, 'sbank'):
            sbank = {}
            for snd in gen.sbank:
                sbank[snd[0]] = dsp.read(snd[1]).data
        else:
            sbank = None

        meta = {
            'midi': midi_devices,
            'param': param_manager,
            'id': voice_id,
            'group': group,
            'sbank': sbank
        }

        if not hasattr(ns, 'reload'):
            setattr(ns, 'reload', False)

        render_process = None

        def render_again(gen, meta, voice_id, ns):
            snd = gen.play(meta)
            setattr(ns, 'buffer-%s' % voice_id, snd)

        iterations = 0
        while getattr(ns, '%s-%s-loop' % (generator, voice_id)) == True:
            meta['iterations'] = iterations
            iterations += 1

            dsp.log('playing %s, id %s, iter %s' %
                    (generator, voice_id, iterations))

            if getattr(ns, 'reload') == True and not hasattr(gen, 'automate'):
                reload(gen)

            # automate will always override play
            if hasattr(gen, 'play') and not hasattr(gen, 'automate'):
                if hasattr(ns, 'buffer-%s' % voice_id):
                    snd = getattr(ns, 'buffer-%s' % voice_id)
                else:
                    # First play render
                    snd = gen.play(meta)

                if render_process is None or not render_process.is_alive():
                    # async start render of next buffer
                    render_process = mp.Process(name='render-%s' % voice_id,
                                                target=render_again,
                                                args=(gen, meta, voice_id, ns))
                    render_process.start()

                snd = dsp.split(snd, 500)

                # if grid is on, wait for a tick to start playback
                if ns.grid:
                    self.tick.wait()

                for s in snd:
                    try:
                        out.write(s)
                    except AttributeError:
                        dsp.log('Could not write to audio device')
                        return False

            if hasattr(gen, 'automate'):
                gen.automate(meta)

                if hasattr(gen, 'loop_time'):
                    time.sleep(gen.loop_time)

        delattr(ns, 'buffer-%s' % voice_id)

        return True
Exemple #7
0
def play(args):
    length = dsp.stf(dsp.rand(5, 10))
    volume = 0.2 
    octave = 2 
    note = 'd'
    quality = tune.major
    reps = dsp.randint(3, 11)
    glitch = False
    superglitch = False
    pulse = False
    ratios = tune.terry

    rhodes = dsp.read('sounds/220rhodes.wav').data

    #scale = [1,3,5,4]
    scale = [1,5,8,6]

    for arg in args:
        a = arg.split(':')

        if a[0] == 't':
            length = dsp.stf(float(a[1]))

        if a[0] == 'v':
            volume = float(a[1]) / 100.0

        if a[0] == 'o':
            octave = int(a[1])

        if a[0] == 'n':
            note = a[1]

        if a[0] == 'q':
            if a[1] == 'M':
                quality = tune.major
            elif a[1] == 'm':
                quality = tune.minor
            else:
                quality = tune.major

        if a[0] == 'r':
            reps = int(a[1])

        if a[0] == 'p':
            pulse = True

        if a[0] == 'g':
            glitch = True

        if a[0] == 'gg':
            glitch = True
            superglitch = True

        if a[0] == 'tr':
            if a[1] == 'young':
                ratios = tune.young
            elif a[1] == 'terry':
                ratios = tune.terry

        if a[0] == 's':
            scale = [int(s) for s in a[1].split('.')]

    out = ''
    for i in range(reps):
        freq = tune.step(i, note, octave, scale, quality, ratios)
        diff = freq / 440.0

        n = dsp.transpose(rhodes, diff)
        n = dsp.fill(n, length)

        o = [dsp.tone(length, freq * i * 0.5) for i in range(4)]
        o = [dsp.env(oo) for oo in o]
        o = [dsp.pan(oo, dsp.rand()) for oo in o]
        o = dsp.mix([dsp.amp(oo, dsp.rand(0.05, 0.1)) for oo in o])
        out += dsp.mix([n, o])

    if glitch == True:
        if superglitch == True:
            mlen = dsp.mstf(100)
        else:
            mlen = dsp.flen(out) / 8

        out = dsp.vsplit(out, dsp.mstf(1), mlen)
        out = [dsp.pan(o, dsp.rand()) for o in out]
        out = ''.join(dsp.randshuffle(out))

    if pulse == True:
        plen = dsp.mstf(dsp.rand(80, 500))
        out = dsp.split(out, plen)
        mpul = len(out) / dsp.randint(4, 8)

        out = [dsp.env(o) * mpul for i, o in enumerate(out) if i % mpul == 0]
        opads = dsp.wavetable('sine', len(out), dsp.rand(plen * 0.25, plen))
        out = [dsp.pad(o, 0, int(opads[i])) for i, o in enumerate(out)]
        out = dsp.env(''.join(out))

    return dsp.cache(dsp.amp(out, volume))