コード例 #1
0
 def playkey(pitch, duration, instrument):
     # Create and play the note
     self.key_dict[key] = CSoundNote(
         onset=0,
         pitch=pitch,
         amplitude=volume,
         pan=0.5,
         duration=duration,
         trackId=track,
         instrumentId=instrument.instrumentId,
         reverbSend=self.reverb,
         tied=True,
         mode='mini')
     self.csnd.play(self.key_dict[key], 0.3)
     if self.getPlayState():
         recOnset = int(self.csnd.loopGetTick())
         self.onset_dict[key] = recOnset
         self.recording(
             CSoundNote(onset=recOnset,
                        pitch=pitch,
                        amplitude=volume,
                        pan=0.5,
                        duration=100,
                        trackId=0,
                        decay=.1,
                        instrumentId=instrument.instrumentId,
                        reverbSend=self.reverb,
                        tied=False,
                        mode='mini'))
コード例 #2
0
ファイル: JamMain.py プロジェクト: leonardcj/tamtam
    def addMetronome(self, page, period):
        self.noteDB.deleteNotesByTrack([page], [1])

        baseCS = CSoundNote(
            0,  # onset
            36,  # pitch
            0.2,  # amplitude
            0.5,  # pan
            100,  # duration
            1,  # track
            self.instrumentDB.instNamed["drum1hatpedal"].instrumentId,
            reverbSend=0.5, tied=True, mode='mini')

        stream = []
        offset = 0

        for b in range(self.noteDB.getPage(page).beats):
            cs = baseCS.clone()
            cs.instrumentId = \
                self.instrumentDB.instNamed["drum1hatshoulder"].instrumentId
            cs.amplitude = 0.5
            cs.onset += offset

            stream.append(cs)

            onset = period
            while onset < Config.TICKS_PER_BEAT:
                cs = baseCS.clone()
                cs.onset = onset + offset
                stream.append(cs)
                onset += period

            offset += Config.TICKS_PER_BEAT

        self.noteDB.addNotes([page, 1, len(stream)] + stream + [-1])
コード例 #3
0
    def send_note(self, inst, pitch, duration, vol, gy=-1):
        if not hasCSound:
            return

        if gy == -1:
            tid = 0
        else:
            tid = self.get_available_track()
            self.track_map[gy] = tid
        pitch = self.shift_pitch(inst, pitch)
        csnote = CSoundNote(0, pitch, vol * self.global_vol, 0.5, duration,
                            tid, inst)
        csnote.decay = 0.5
        self.csound.play(
            csnote,
            1)  # sec per tick = 1, so the unit for duration/decay becomes sec
コード例 #4
0
    def send_tied_note_off(self, inst, pitch, duration, decay, vol):
        if not hasCSound:
            return

        tid = self.query_pitch_and_recycle_tid(pitch)
        if tid == -1:
            return
        #print "pitch(" + str(pitch) + ") removed from track " + str(tid)
        pitch = self.shift_pitch(inst, pitch)

        csnote = CSoundNote(0, pitch, vol * self.global_vol, 0.5, duration,
                            tid, inst)
        csnote.decay = decay
        csnote.tied = False
        csnote.mode = "mini"

        self.csound.play(csnote, 1)
コード例 #5
0
    def send_tied_note_on(
        self, inst, pitch, vol
    ):  # tied note generates a pair of note_on/off event, in note_on, duration = -1 (open note)
        if not hasCSound:
            return

        tid = self.get_available_track()
        self.track_map[pitch] = tid
        #print "pitch(" + str(pitch) + ") on track " + str(tid)
        pitch = self.shift_pitch(inst, pitch)

        csnote = CSoundNote(0, pitch, vol * self.global_vol, 0.5, -1, tid,
                            inst)
        csnote.tied = True
        csnote.mode = "mini"

        self.csound.play(csnote, 1)
コード例 #6
0
    def send_loop_note(self, inst, pitch, time, duration, vol, lid):
        if not hasCSound:
            return

        #generate a CSoundNote: (onset_time (ticks), pitch (MIDI #), vol, pan, duration (ticks), track_id, inst_id)
        pitch = self.shift_pitch(inst, pitch)
        csnote = CSoundNote(time, pitch, vol * self.global_vol, 0.5, duration,
                            0, inst)
        if inst < 5:  # sustain piano sound for 0.15 sec
            csnote.duration = duration + self.time2tick(0.36)
        #elif inst == 141:
        #    csnote.duration = -1
        csnote.decay = self.time2tick(
            0.75)  # apply a decay for all instruments

        #wrap it in a Note before adding to the loop Note(page_id, track_id, note_id, csnote)
        n = Note(0, csnote.trackId, self.get_nid(), csnote)
        self.csound.loopPlay(n, 1, loopId=lid)
コード例 #7
0
 def playInstrumentNote(self, instrument, secs_per_tick=0.025):
     if not self.muteInst:
         self.csnd.play(
             CSoundNote(onset=0,
                        pitch=36,
                        amplitude=1,
                        pan=0.5,
                        duration=20,
                        trackId=1,
                        instrumentId=self.instrumentDB.
                        instNamed[instrument].instrumentId,
                        reverbSend=self.reverb,
                        tied=False,
                        mode='mini'), secs_per_tick)
コード例 #8
0
    def note_add(self, argv):
        if Config.DEBUG > 3: print 'note_add', argv

        nid = int(argv[0])
        page = self.pid[int(argv[1])]
        track = int(argv[2])
        instId = self.noteDB.getPage(page).instruments[track]
        cs = CSoundNote(int(argv[3]), int(argv[4]), float(argv[5]),
                        float(argv[6]), float(argv[7]), int(argv[8]), instId,
                        float(argv[10]), float(argv[11]), float(argv[12]),
                        float(argv[13]), float(argv[14]), bool(argv[15]),
                        argv[16])

        self.noteDB.addNote(-1, page, track, cs)
コード例 #9
0
    def addMetronome(self, page, period):
        self.noteDB.deleteNotesByTrack([page], [1])

        baseCS = CSoundNote(
            0,  # onset
            36,  # pitch
            0.2,  # amplitude
            0.5,  # pan
            100,  # duration
            1,  # track
            self.instrumentDB.instNamed["drum1hatpedal"].instrumentId,
            reverbSend=0.5,
            tied=True,
            mode='mini')

        stream = []
        offset = 0

        for b in range(self.noteDB.getPage(page).beats):
            cs = baseCS.clone()
            cs.instrumentId = \
                self.instrumentDB.instNamed["drum1hatshoulder"].instrumentId
            cs.amplitude = 0.5
            cs.onset += offset

            stream.append(cs)

            onset = period
            while onset < Config.TICKS_PER_BEAT:
                cs = baseCS.clone()
                cs.onset = onset + offset
                stream.append(cs)
                onset += period

            offset += Config.TICKS_PER_BEAT

        self.noteDB.addNotes([page, 1, len(stream)] + stream + [-1])
コード例 #10
0
    def pageGenerate( regularity, drumPitch ):
        barLength = Config.TICKS_PER_BEAT * nbeats

        #print 'pageGenerate drumPitch[0] ', drumPitch[0]
        currentInstrument = instrumentDB.instNamed[ instrument ].kit[ drumPitch[0] ]

        rythmSequence = makeRythm.drumRythmSequence(currentInstrument, nbeats, density, regularity)
        pitchSequence = makePitchSequence(len(rythmSequence), drumPitch )
        gainSequence = makeGainSequence(rythmSequence)

        trackNotes = []
        list = range(len(rythmSequence))
        for i in list:
            trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i],
                                           pan, noteDuration, trackId,
                                           instrumentDB.instNamed[instrument].instrumentId, attack,
                                           decay, reverbSend, filterType, filterCutoff, tied, mode))
        return trackNotes
コード例 #11
0
 def createCsNote(self, i, instrument, reverb):
     onset = i[0]
     pitch = i[1]
     gain = i[2]*self.volume
     duration = i[3]
     if self.instrumentDB.instNamed[instrument].kit != None:
         if GenerationConstants.DRUMPITCH.has_key(pitch):
             pitch = GenerationConstants.DRUMPITCH[pitch]
         instrument = self.instrumentDB.instNamed[ instrument ].kit[pitch].name
         pitch = 36
     return CSoundNote( onset = onset,
                 pitch = pitch,
                 amplitude = gain,
                 pan = 0.5,
                 duration = duration,
                 trackId = 0,
                 instrumentId = self.instrumentDB.instNamed[instrument].instrumentId,
                 reverbSend = reverb,
                 tied = False,
                 mode = 'mini')
コード例 #12
0
    def _playNote(self, key, pitch, amplitude, pan, duration, instrumentId,
                  reverb):
        self.key_dict[key] = CSoundNote(
            # onset
            0,
            pitch,
            amplitude,
            pan,
            duration,
            self.nextTrack,
            instrumentId,
            reverbSend=reverb,
            tied=True,
            mode='mini')
        self.nextTrack += 1
        if self.nextTrack > 8:
            self.nextTrack = 2
        self.csnd.play(self.key_dict[key], 0.3)

        return self.key_dict[key]
コード例 #13
0
    def pageGenerate(parameters,
                     trackId,
                     pageId,
                     trackOfNotes,
                     drumPitch=None):

        trackNotes = trackOfNotes

        if drumPitch:
            currentInstrument = instrumentDB.instNamed[
                instrument[pageId][trackId]].kit[drumPitch[0]]
            rythmSequence = makeRythm.drumRythmSequence(
                parameters, currentInstrument, barLength)
            pitchSequence = makePitch.drumPitchSequence(
                len(rythmSequence), parameters, drumPitch, table_pitch)
        else:
            currentInstrument = instrument[pageId][trackId]
            rythmSequence = makeRythm.celluleRythmSequence(
                parameters, barLength, trackId, currentInstrument)
            pitchSequence = makePitch.drunkPitchSequence(
                len(rythmSequence), parameters, table_pitch, trackId)

        gainSequence = makeGainSequence(rythmSequence)
        durationSequence = makeDurationSequence(rythmSequence, parameters,
                                                table_duration, barLength,
                                                currentInstrument)

        numOfNotes = range(len(rythmSequence))
        rand = random.random
        append = trackNotes.append
        pan = GenerationConstants.DEFAULT_PAN
        instrument_id = instrumentDB.instNamed[instrument[pageId]
                                               [trackId]].instrumentId
        for i in numOfNotes:
            if drumPitch:
                if (rand() * fillDrum) > (parameters.silence[0] * .5):
                    if fillDrum != 1:
                        if rythmSequence[i] not in trackOnsets or pitchSequence[
                                i] not in trackPitchs:
                            append(
                                CSoundNote(rythmSequence[i], pitchSequence[i],
                                           gainSequence[i], pan,
                                           durationSequence[i], trackId,
                                           instrument_id, 0.002, 0.098, 0.1, 0,
                                           1000, False, 'edit'))
                    else:
                        append(
                            CSoundNote(rythmSequence[i], pitchSequence[i],
                                       gainSequence[i], pan,
                                       durationSequence[i], trackId,
                                       instrument_id, 0.002, 0.098, 0.1, 0,
                                       1000, False, 'edit'))
            else:
                if rand() > parameters.silence[trackId]:
                    append(
                        CSoundNote(rythmSequence[i], pitchSequence[i],
                                   gainSequence[i], pan, durationSequence[i],
                                   trackId, instrument_id, 0.002, 0.1, 0.1, 0,
                                   1000, False, 'edit'))

        trackDictionary[trackId][pageId] = trackNotes