示例#1
0
    def __init__(
        self,
        strings: tuple,
        midi_synth: midi.MidiSynth,
        spat_maker: spat.BalancedSpatMaker,
        n_voices: int = 4,
    ):
        super().__init__()
        self._mixer = pyo.Mixer(outs=4, chnls=1, time=0.025)

        self._markov_chains = self._make_markov_chains()

        self._midi_synth = midi_synth
        self.strings = strings
        self._generators = [GenderGenerator() for _ in range(n_voices)]
        self._generator_idx_cycle = infit.Cycle(range(n_voices))
        self._spatialised_generators = [
            spat_maker.make_spatialised_signal(gen, n_voices=4)
            for gen in self._generators
        ]
        self._summed_generators = sum(self._spatialised_generators)
        self._previous_played_pitches = collections.deque([], maxlen=15)

        self._trig_func = pyo.TrigFunc(
            tuple(self.strings.values())[0].attack_detector, self.trigger_events
        )
        self._trig_func.stop()

        self._add_summed_generators_to_mixer()
示例#2
0
 def __init__(self, **args):
     pyo.EventInstrument.__init__(self, **args)
     self.osc = pyo.LFO(freq=self.freq, sharp=1, type=2, mul=self.env)
     self.mixer = pyo.Mixer()
     self.mixer.addInput(0, self.osc)
     self.mixer.setAmp(0, 0, 0.5)
     self.mixer.setAmp(0, 1, 0.5)
     self.mixer.out()
示例#3
0
    def __init__(self, n_voices: int):
        self._voice_cycle = itertools.cycle(range(n_voices))
        self._generators = tuple(self._generator_class()
                                 for _ in range(n_voices))
        self.mixer = pyo.Mixer(1, chnls=self._nchnls_per_generator)

        for nth_gen, generator in enumerate(self.generators):
            self.mixer.addInput(nth_gen, generator.generator)
            self.mixer.setAmp(nth_gen, 0, 1)
示例#4
0
 def init_mixer(self,
                identifier,
                file_path,
                loop=False,
                amp=0.1,
                channels=None):
     sf = pyo.SfPlayer(file_path, loop=loop)
     mixer = pyo.Mixer(outs=self.channels, chnls=1)
     mixer.addInput(0, sf)
     for o in range(self.channels):
         mixer.setAmp(0, o, amp)
     self.mixers[identifier] = mixer
     self.files[identifier] = sf
     if channels is not None:
         self.set_mixer(identifier, channels)
     mixer.out()
     sf.play()
示例#5
0
    def __init__(self, strings: dict, midi_synth: object):
        super().__init__()

        self.strings = strings
        self.midi_synth = midi_synth
        self._mixer = pyo.Mixer(outs=4, chnls=1, time=0.025)

        self.instrument2channel_mapping = {
            instrument: (tuple(range(n, n + 4)), tuple(range(4)))
            for instrument, n in zip(self.strings,
                                     range(0, 4 * len(self.strings), 4))
        }

        for instrument_name, instrument_object in self.strings.items():
            for input_chnl, output_chnl in zip(
                    *self.instrument2channel_mapping[instrument_name]):
                self.mixer.addInput(input_chnl,
                                    instrument_object.processed_signal)
                self.mixer.setAmp(input_chnl, output_chnl, 0)
示例#6
0
    SERVER = pyo.Server(
        audio="jack", midi="jack", nchnls=len(settings.PHYSICAL_OUTPUT2CHANNEL_MAPPING),
    )

    # listening / sending to all midi output devices
    SERVER.setMidiInputDevice(99)
    SERVER.setMidiOutputDevice(99)

    # starting server
    SERVER.boot()

    import gender_player
    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 = {
示例#7
0
    def __init__(self, server: pyo.Server, midi_data_logger):
        self.midi_data_logger = midi_data_logger
        self.server = server
        self.previous_hauptstimme_instrument = set([])
        self.instrument_change_trigger = pyo.Trig()

        self.pianoteq_trigger = pyo.Trig()

        self.sine_mixer = pyo.Mixer(outs=3, chnls=1, mul=0.3)
        self.sine_radio_mixer = pyo.Mixer(outs=4, chnls=1, mul=0.3)
        self.gong_mixer = pyo.Mixer(outs=4, chnls=1, time=0.05, mul=1)

        self.transducer_synth = TransducerSynth(
            self._n_voices_for_transducer_synth)
        self.gong_synth = GongSynth(self._n_voices_for_gong_synth)
        self.kenong_synth = KenongSynth(self._n_voices_for_kenong_synth)

        self.pitch_stack = PitchStack()

        # sending transducer outputs to sine mixer & sine radio mixer
        for n in range(3):
            signal = self.transducer_synth.mixer[0][n]
            self.sine_mixer.addInput(n, signal)
            self.sine_mixer.setAmp(n, n, 1)

            self.sine_radio_mixer.addInput(n, signal)

            for m in range(4):
                # TODO(which amp?)
                self.sine_mixer.setAmp(n, m, 1)
                self.sine_radio_mixer.setAmp(n, m, 1)

        # sending gong outputs and kenong outputs to gong mixer
        for n, mixer in enumerate(
            (self.kenong_synth.mixer, self.gong_synth.mixer)):
            added = 4 * n
            for n in range(4):
                signal = mixer[0][n]
                self.gong_mixer.addInput(n + added, signal)
                self.gong_mixer.setAmp(n + added, n, 1)

        # sending all transducer and gong inputs out
        for mixer, mixer2channel_mapping in (
            (self.sine_mixer, settings.SINE_MIXER_INSTRUMENT2CHANNEL_MAPPING),
            (
                self.sine_radio_mixer,
                settings.SINE_TO_RADIO_MIXER_INSTRUMENT2CHANNEL_MAPPING,
            ),
            (self.gong_mixer, settings.GONG_MIXER2CHANNEL_MAPPING),
        ):
            [mixer[i][0].play() for i in mixer2channel_mapping.values()]

        self.notes = pyo.Notein(
            poly=self._n_voices,
            last=self._last_midi_note,
            channel=0,
        )
        self.trigger_on = pyo.TrigFunc(
            self.notes["trigon"],
            self._trigger_on_function,
            arg=list(range(self._n_voices)),
        )
        self.trigger_off = pyo.TrigFunc(
            self.notes["trigoff"],
            self._trigger_off_function,
            arg=list(range(self._n_voices)),
        )

        self.sustain_pedal = pyo.Midictl(
            settings.KEYBOARD_PEDAL_CTRL_NUMBER,
            0,
            1,
            init=0,
            channel=settings.KEYBOARD_CHANNEL,
        )
    def __init__(self, master=None, experiment=[], logger=None):
        
        ###########################
        # INIT EXPERIMENT
        ###########################
        self.experiment=experiment

        
        ###########################
        # INIT LOGGING
        ###########################
        self.logger=logger
        self.currentTrial = 0
        self.currentBlock = 0
        self.blockType = 0
        self.mouse = 0
        
        ###########################
        # INIT TIMING
        ###########################
        #self.t = timr(1, self.runexperiment) #placeholder to make sure the variable exists
        self.timers = []
        
        ###########################
        # INIT VISUAL
        ###########################
        self.waitForRatingAnswer = False
        self.waitForRatingAnswer2 = False
        self.numRects = 4
        self.rects=range(self.numRects)
        self.screenWidth = 640
        self.screenHeight = 480
        Frame.__init__(self,master)
        self.grid()
        self.userPrompt = StringVar()
        
        # moved these up here so they only happen once
        pianoimage = Image.open(KEYBOARD_IMAGE)
        self.pianoImage = ImageTk.PhotoImage(pianoimage)
        sliderimage = Image.open(SLIDER_IMAGE)
        self.sliderImage = ImageTk.PhotoImage(sliderimage)
        self.fingerString = StringVar()
        self.qString = StringVar()
        self.countString = StringVar()

        self.create_GUI()

        
        ###########################
        # INIT AUDI
        ###########################
        self.s = pyo.Server(buffersize = 8, nchnls = 1)
        
        # before booting the server, I'll prompt the user to choose an input device
        # NOTE: This can be hard-coded later if you always want it to choose a specific MIDI input device
#         pyo.pm_list_devices()
#         self.choice = input("Which device will you choose?")        
#         self.s.setMidiInputDevice(int(self.choice))
    
        self.s.setMidiInputDevice(int(3))
        
        self.s.boot()        
        self.s.start()
        
#         test = pyo.LFO(freq=440.0).out()
        
        time.sleep(1) # settling time
        
#         test.stop()
        
        # MIDI Stuff
        self.refnote = 72
        self.polynum = 4
        self.pianosound = range(self.polynum)
        self.notes = pyo.Notein(poly=self.polynum, scale=0, mul=0.5)
        self.enablePlayback = False
        self.enableNoteLogging = False
        self.noteTrig = pyo.TrigFunc(self.notes['trigon'],self.onNoteon,range(self.polynum))
        #for p in range(polynum):
        
        # note trigger mixer
        self.trigmix = pyo.Mixer(1,self.polynum)
        for p in range(self.polynum):
            self.trigmix.addInput(p,self.notes['trigon'][p])
            self.trigmix.setAmp(p,0,1.0)
        self.polyNoteTrig = self.trigmix[0]
            
        global midikeymapping # needs to be visible everywhere
        midikeymapping = 1 # set mapping to 1 to start with

        # preload sound files
        self.melodies = []
        self.extract = []
        
        for i in range(self.polynum):
            self.pianosound[i] = pyo.SfPlayer(EXTRACT_DIR + PIANO_FILE[0], speed=1, loop=False, offset=0, interp=2, mul=1, add=0)                
        for fname in STIM_FILES:
            self.melodies.append(pyo.SfPlayer(STIM_DIR + fname, mul=0.5))
        for fname in EXTRACT_FILES:
            self.extract.append(pyo.SfPlayer(EXTRACT_DIR + fname, mul=0.5))
        self.metronome = pyo.SfPlayer(EXTRACT_DIR + METRO_FILE[0], mul=0.5)
        
        # prepare sequence and timing triggers
        # metroSeq launches the metronome
        self.trialMetroSeq = pyo.Seq(time=NOTEDUR/1000.0, seq=[3,3,3,1], poly=1, onlyonce=True, speed=1)
        self.expectedKeySeq = pyo.Seq(time=NOTEDUR/1000.0, seq=[9,1,1,1,1], poly=1, onlyonce=True, speed=1)
        # trialStartTrigger will be manually launched when we want to start a trial
        self.trialStartTrigger = pyo.Trig().stop()
        self.warmuptrialStartTrigger = pyo.Trig().stop()
        self.dummyTrigger = pyo.Trig().stop()
        self.timerLogsEnabled = False
        # eventTimer will measure the time between trial events
        # eventTimer is initially triggered by the trial start, but will later be switched to measure between note events
        self.trialEventTimer = pyo.Timer(self.polyNoteTrig,self.trialStartTrigger)
        self.expectedEventTimer = pyo.Timer(self.expectedKeySeq,self.expectedKeySeq)
        self.timerMeasurement = pyo.DataTable(1)
        self.lastTimerMeasurement = 0.0
        self.expectedMeasurement = pyo.DataTable(1)
        self.lastExpectedMeasurement = 0.0
        self.measurementRecorder = pyo.TablePut(self.trialEventTimer, self.timerMeasurement).play()
        self.expectedRecorder = pyo.TablePut(self.expectedEventTimer, self.expectedMeasurement).play()
        self.resetAtStim = False

        
        # triggers for the optimized stim delivery
        self.t1 = pyo.TrigFunc(self.trialStartTrigger,self.playAudioExtract)
        self.t2 = pyo.TrigFunc(self.trialStartTrigger,self.trialMetroSeq.out)
        self.t2b = pyo.TrigFunc(self.trialStartTrigger,self.expectedKeySeq.out)
        self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.playMetronome)
#         self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.metronome.out)
        self.t4 = pyo.TrigFunc(self.polyNoteTrig,self.noteTiming)
        self.t5 = pyo.TrigFunc(self.expectedKeySeq,self.expectedTiming)

        # triggers for the optimized stim delivery in training
        #self.t1 = pyo.TrigFunc(self.warmuptrialStartTrigger,self.playAudioExtract)
        self.t6 = pyo.TrigFunc(self.warmuptrialStartTrigger,self.trialMetroSeq.out)
        self.t7 = pyo.TrigFunc(self.warmuptrialStartTrigger,self.expectedKeySeq.out)
#         self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.playMetronome)
#         self.t3 = pyo.TrigFunc(self.trialMetroSeq,self.metronome.out)
#         self.t4 = pyo.TrigFunc(self.notes['trigon'],self.noteTiming)
#         self.t5 = pyo.TrigFunc(self.expectedKeySeq,self.expectedTiming)

        
        ###########################
        # INIT INPUT DEVICES
        ###########################
        self.set_keybinds()
        self.waitForSpacebar = True

        ############################
        self.enableAudioFeedback = False
        self.QUIT = False
        self.pause = False