diff options
author | Oli2 <olivier.belanger@umontreal.ca> | 2007-03-11 20:12:11 (GMT) |
---|---|---|
committer | Oli2 <olivier.belanger@umontreal.ca> | 2007-03-11 20:12:11 (GMT) |
commit | 15b8185ad77206c8aafc7cf8f0fb98b60d0792b4 (patch) | |
tree | 7a1b7593db8a9ee7830b87f221eb6d46cbcce719 /miniTamTam | |
parent | 23a442a71a03295c05fe9eae834357767266b9c0 (diff) |
algo stuff in miniT ( fillin )
Diffstat (limited to 'miniTamTam')
-rw-r--r-- | miniTamTam/Fillin.py | 90 | ||||
-rw-r--r-- | miniTamTam/GenRythm.py | 41 | ||||
-rw-r--r-- | miniTamTam/MiniSequencer.py | 2 | ||||
-rw-r--r-- | miniTamTam/RythmGenerator.py | 47 | ||||
-rw-r--r-- | miniTamTam/miniTamTamMain.py | 8 |
5 files changed, 127 insertions, 61 deletions
diff --git a/miniTamTam/Fillin.py b/miniTamTam/Fillin.py new file mode 100644 index 0000000..2fe7578 --- /dev/null +++ b/miniTamTam/Fillin.py @@ -0,0 +1,90 @@ +import pygtk +pygtk.require( '2.0' ) +import gtk +import gobject + +from RythmGenerator import * +from Util.CSoundClient import new_csound_client +from Util.NoteDB import Note +import Config + +class Fillin: + def __init__( self, nbeats, tempo, instrument, reverb ): + self.notesList = [] + self.barCount = 0 + self.gate = 0 + self.nbeats = nbeats + self.tempo = tempo + self.instrument = instrument + self.reverb = reverb + self.playBackTimeout = None + self.csnd = new_csound_client() + + def reset( self ): + self.barCount = 0 + self.gate = 0 + + def setInstrument( self, instrument ): + self.instrument = instrument + + def setBeats( self, nbeats ): + self.nbeats = nbeats + self.clear() + self.reset() + + def setTempo( self, tempo ): + self.tempo = tempo + if self.playBackTimeout != None: + gobject.source_remove( self.playBackTimeout ) + self.play() + + def setReverb( self, reverb ): + self.reverb = reverb + + def play( self ): + if self.playBackTimeout == None: + self.playbackTimeout = gobject.timeout_add( int(60000/self.tempo/8), self.handleClock ) + self.handleClock() + + def stop( self ): + if self.playBackTimeout != None: + gobject.source_remove( self.playBackTimeout ) + self.clear() + + def clear( self ): + if self.notesList: + for n in self.notesList: + self.csnd.loopDelete(n) + self.notesList = [] + + def handleClock( self ): + tick = self.csnd.loopGetTick() + if tick < ( Config.TICKS_PER_BEAT / 2 + 1 ): + if self.gate == 0: + self.gate = 1 + self.barCount += 1 + self.barCount %= 4 + if self.barCount == 1: + self.clear() + + if tick > ( ( Config.TICKS_PER_BEAT * self.nbeats ) - ( Config.TICKS_PER_BEAT / 2 ) - 1 ): + if self.gate == 1: + self.gate = 0 + if self.barCount == 3: + self.regenerate() + return True + + def regenerate(self): + def flatten(ll): + rval = [] + for l in ll: + rval += l + return rval + i = 500 + self.notesList= [] + for x in flatten( generator(self.instrument, self.nbeats, 0, self.reverb) ): + n = Note(0, x.trackId, i, x) + self.notesList.append(n) + i += 1 + self.csnd.loopPlay(n,1) #add as active + diff --git a/miniTamTam/GenRythm.py b/miniTamTam/GenRythm.py index 0cba969..eba0eb8 100644 --- a/miniTamTam/GenRythm.py +++ b/miniTamTam/GenRythm.py @@ -5,13 +5,7 @@ from Generation.GenerationConstants import GenerationConstants from Generation.Utils import * class GenRythm: - def __init__( self, instrument, barLength, nbeats ): - self.instrument = instrument - self.barLength = barLength - self.nbeats = nbeats - -############################################################################# - def drumRythmSequence(self, regularity ): + def drumRythmSequence(self, instrument, nbeats, regularity ): rythmSequence = [] binSelection = [] downBeats = [] @@ -20,52 +14,37 @@ class GenRythm: density = 0.8 countDown = 0 onsetTime = None - beatsPerPage = int( self.barLength / Config.TICKS_PER_BEAT ) - if Config.INSTRUMENTS[ self.instrument ].instrumentRegister == Config.PUNCH: + if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.PUNCH: registerDensity = 0.5 downBeatRecurence = 4 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.PUNCH_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_PUNCH_PROB[ nbeats ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT , downBeat[ 1 ] ) ) - if Config.INSTRUMENTS[ self.instrument ].instrumentRegister == Config.LOW: + if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.LOW: registerDensity =1.5 downBeatRecurence = 4 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.LOW_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_LOW_PROB[ nbeats ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 2 , downBeat[ 1 ] ) ) - if Config.INSTRUMENTS[ self.instrument ].instrumentRegister == Config.MID: + if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.MID: registerDensity = .75 downBeatRecurence = 1 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - beats.append( beat * Config.TICKS_PER_BEAT + ( Config.TICKS_PER_BEAT / 2 ) ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.MID_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_MID_PROB[ nbeats ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) - if Config.INSTRUMENTS[ self.instrument ].instrumentRegister == Config.HIGH: + if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.HIGH: registerDensity = 1.5 downBeatRecurence = 1 - for beat in range( beatsPerPage ): - beats.append( beat * Config.TICKS_PER_BEAT ) - beats.append( beat * Config.TICKS_PER_BEAT + ( Config.TICKS_PER_BEAT / 2 ) ) - for i in range( len( beats ) ): - downBeats.append( ( beats[ GenerationConstants.HIGH_ACCENTS[ beatsPerPage ][ i ] ], pow( float( len( beats ) - i) / len( beats ), 1.5 ) * 100.) ) + downBeats = GenerationConstants.DRUM_HIGH_PROB[ nbeats ] for downBeat in downBeats: upBeats.append( ( downBeat[ 0 ] + Config.TICKS_PER_BEAT / 4 , downBeat[ 1 ] ) ) for i in range( int( density * registerDensity * len( downBeats ) ) ): - if random.randint( 0, 100 ) < ( regularity * 100 * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): + if random.random() < ( regularity * downBeatRecurence ) and binSelection.count( 1 ) < len( downBeats ): binSelection.append( 1 ) else: if binSelection.count( 0 ) < len( downBeats ): diff --git a/miniTamTam/MiniSequencer.py b/miniTamTam/MiniSequencer.py index 1e40aac..8a99606 100644 --- a/miniTamTam/MiniSequencer.py +++ b/miniTamTam/MiniSequencer.py @@ -15,7 +15,6 @@ class MiniSequencer: self.pitchs = [] self.beat = 4 self.tempo = Config.PLAYER_TEMPO - self.tickDuration = 60. / self.tempo / 12. self.tick = 15 self.id = 1000 self.csnd = new_csound_client() @@ -27,7 +26,6 @@ class MiniSequencer: def setTempo( self, tempo ): self.tempo = tempo - self.tickDuration = 60. / self.tempo / 12. gobject.source_remove( self.playBackTimeout ) self.playState = 0 diff --git a/miniTamTam/RythmGenerator.py b/miniTamTam/RythmGenerator.py index c259463..b7fb21b 100644 --- a/miniTamTam/RythmGenerator.py +++ b/miniTamTam/RythmGenerator.py @@ -8,6 +8,18 @@ from GenRythm import GenRythm def generator( instrument, nbeats, regularity, reverbSend ): + makeRythm = GenRythm() + + noteDuration = GenerationConstants.DOUBLE_TICK_DUR / 2 + trackId = 5 + pan = 0.5 + attack = 0.005 + decay = 0.095 + filterType = 0 + filterCutoff = 1000 + tied = False + mode = 'mini' + def makePitchSequence(length, drumPitch): pitchSequence = [] for i in range(length): @@ -26,55 +38,34 @@ def generator( instrument, nbeats, regularity, reverbSend ): gainSequence.append(gain*2) return gainSequence - def makeDurationSequence( onsetList ): - durationSequence = [] - if len( onsetList ) > 1: - for i in range(len(onsetList)): - duration = GenerationConstants.DOUBLE_TICK_DUR / 2 - durationSequence.append(duration) - elif len( onsetList ) == 1: - durationSequence.append( GenerationConstants.DOUBLE_TICK_DUR / 2 ) - return durationSequence - def pageGenerate( regularity, drumPitch ): barLength = Config.TICKS_PER_BEAT * nbeats if Config.INSTRUMENTS[instrument].kit != None: currentInstrument = Config.INSTRUMENTS[instrument].kit[drumPitch[0]].name - makeRythm = GenRythm( currentInstrument, barLength, nbeats ) - - rythmSequence = makeRythm.drumRythmSequence(regularity) + rythmSequence = makeRythm.drumRythmSequence(currentInstrument, nbeats, regularity) pitchSequence = makePitchSequence(len(rythmSequence), drumPitch ) gainSequence = makeGainSequence(rythmSequence) - durationSequence = makeDurationSequence(rythmSequence) - trackId = 5 - pan = 0.5 - attack = 0.005 - decay = 0.095 - filterType = 0 - filterCutoff = 1000 - tied = False - mode = 'mini' trackNotes = [] for i in range(len(rythmSequence)): trackNotes.append( CSoundNote( rythmSequence[i], pitchSequence[i], gainSequence[i], - pan, durationSequence[i], trackId, + pan, noteDuration, trackId, Config.INSTRUMENTS[instrument].instrumentId, attack, decay, reverbSend, filterType, filterCutoff, tied, mode ) ) return trackNotes ################################################################################## # begin generate() if regularity > 0.75: - pitchOfStream = [ [ 24 ], [30] , [ 40 ], [ 46 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY1 elif regularity > 0.5: - pitchOfStream = [ [ 24, 28 ], [ 30, 32 ], [ 36, 38, 40 ], [ 46, 48 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY2 elif regularity > 0.25: - pitchOfStream = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 46, 48 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY3 else: - pitchOfStream = [ [ 24, 26, 28 ], [ 30, 32, 34 ], [ 38, 40 ], [ 42, 44, 46, 48 ] ] + streamOfPitch = GenerationConstants.DRUM_COMPLEXITY4 trackNotes = [] - for drumPitch in pitchOfStream: + for drumPitch in streamOfPitch: trackNotes.append(pageGenerate( regularity, drumPitch )) return trackNotes diff --git a/miniTamTam/miniTamTamMain.py b/miniTamTam/miniTamTamMain.py index 9bde947..64ed76c 100644 --- a/miniTamTam/miniTamTamMain.py +++ b/miniTamTam/miniTamTamMain.py @@ -15,6 +15,7 @@ from Util import NoteDB from Util.NoteDB import Note from Util.CSoundClient import new_csound_client +from Fillin import Fillin from KeyboardStandAlone import KeyboardStandAlone from MiniSequencer import MiniSequencer from RythmGenerator import * @@ -42,6 +43,7 @@ class miniTamTamMain(SubActivity): self.tempo = Config.PLAYER_TEMPO self.rythmInstrument = 'drum1kit' self.regenerate() + self.drumFillin = Fillin( self.beat, self.tempo, self.rythmInstrument, self.reverb ) self.sequencer= MiniSequencer(self.recordStateButton) self.csnd.loopSetTempo(self.tempo) self.noteList = [] @@ -300,12 +302,14 @@ class miniTamTamMain(SubActivity): def handleBeatSliderRelease(self, widget, event): self.beat = int(widget.get_adjustment().value) self.sequencer.beat = self.beat + self.drumFillin.setBeats( self.beat ) self.regenerate() def handleTempoSliderRelease(self, widget, event): #self.tempo = int(widget.get_adjustment().value) #self.csnd.loopSetTempo(self.tempo) self.sequencer.tempo = widget.get_adjustment().value + self.drumFillin.setTempo(self.tempo) pass def handleTempoSliderChange(self,adj): @@ -325,16 +329,19 @@ class miniTamTamMain(SubActivity): def handleReverbSlider(self, adj): self.reverb = adj.value + self.drumFillin.setReverb( self.reverb ) img = int(self.scale(self.reverb,0,1,0,4)) self.reverbSliderBoxImgTop.set_from_file(Config.IMAGE_ROOT + 'reverb' + str(img) + '.png') self.keyboardStandAlone.setReverb(self.reverb) def handlePlayButton(self, widget, data = None): if widget.get_active() == False: + self.drumFillin.stop() self.sequencer.stopPlayback() self.playbackTimeout = None self.csnd.loopPause() else: + self.drumFillin.play() self.csnd.loopSetTick(0) self.csnd.loopStart() @@ -345,6 +352,7 @@ class miniTamTamMain(SubActivity): instrumentId = Config.INSTRUMENTS[data].instrumentId for (o,n) in self.noteList : self.csnd.loopUpdate(n, NoteDB.PARAMETER.INSTRUMENT, instrumentId, -1) + self.drumFillin.setInstrument( self.rythmInstrument ) def handleGenerateBtn(self , widget , data=None): self.regenerate() |