diff options
author | Oli <olivier.belanger@umontreal.ca> | 2007-07-18 23:04:25 (GMT) |
---|---|---|
committer | Oli <olivier.belanger@umontreal.ca> | 2007-07-18 23:04:25 (GMT) |
commit | b7a6ecf47a6090b5fa4566f9a5e1147d1a099ba3 (patch) | |
tree | 6de79963687f7cfb22e8028a9feb5023664c8f22 /miniTamTam | |
parent | 79b3ce7fff88482831a145d7563460389f7de755 (diff) | |
parent | 89f7701457b2222b2d3eaee7ee00285f9f52991a (diff) |
Merge branch 'master' of git+ssh://olipet@dev.laptop.org/git/projects/tamtam
Diffstat (limited to 'miniTamTam')
-rw-r--r-- | miniTamTam/GenRythm.py | 12 | ||||
-rw-r--r-- | miniTamTam/KeyboardStandAlone.py | 89 | ||||
-rwxr-xr-x | miniTamTam/Loop.py | 7 | ||||
-rw-r--r-- | miniTamTam/miniTamTamMain.py | 53 |
4 files changed, 90 insertions, 71 deletions
diff --git a/miniTamTam/GenRythm.py b/miniTamTam/GenRythm.py index 5e4a873..a9d8f70 100644 --- a/miniTamTam/GenRythm.py +++ b/miniTamTam/GenRythm.py @@ -4,8 +4,10 @@ import Config from Generation.GenerationConstants import GenerationConstants from Generation.Utils import * +from Util import Instrument + class GenRythm: - def drumRythmSequence(self, instrument, nbeats, density, regularity ): + def drumRythmSequence(self, instrumentName, nbeats, density, regularity ): rythmSequence = [] binSelection = [] downBeats = [] @@ -14,28 +16,28 @@ class GenRythm: countDown = 0 onsetTime = None - if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.PUNCH: + if Instrument.INST[instrumentName].register == 'punch': registerDensity = 0.5 downBeatRecurence = 4 downBeats = [x for x in GenerationConstants.DRUM_PUNCH_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) - if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.LOW: + if Instrument.INST[instrumentName].register == 'low': registerDensity =1 downBeatRecurence = 4 downBeats = [x for x in GenerationConstants.DRUM_LOW_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 2 ) - if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.MID: + if Instrument.INST[instrumentName].register == 'mid': registerDensity = .75 downBeatRecurence = 1 downBeats = [x for x in GenerationConstants.DRUM_MID_ACCENTS[ nbeats ]] for downBeat in downBeats: upBeats.append( downBeat + Config.TICKS_PER_BEAT / 4 ) - if Config.INSTRUMENTS[ instrument ].instrumentRegister == Config.HIGH: + if Instrument.INST[instrumentName].register == 'high': registerDensity = 1.5 downBeatRecurence = 1 downBeats = [x for x in GenerationConstants.DRUM_HIGH_ACCENTS[ nbeats ]] diff --git a/miniTamTam/KeyboardStandAlone.py b/miniTamTam/KeyboardStandAlone.py index b783070..a5f7c49 100644 --- a/miniTamTam/KeyboardStandAlone.py +++ b/miniTamTam/KeyboardStandAlone.py @@ -7,9 +7,12 @@ from Generation.GenerationConstants import GenerationConstants from Util.NoteDB import Note from Util.CSoundNote import CSoundNote from Util.CSoundClient import new_csound_client +from Util import Instrument KEY_MAP_PIANO = Config.KEY_MAP_PIANO +log = file('/home/olpc/log.tamtam','w') + class KeyboardStandAlone: def __init__( self, recordingFunction, adjustDurationFunction, getCurrentTick, getPlayState, loop ): self.csnd = new_csound_client() @@ -58,53 +61,53 @@ class KeyboardStandAlone: self.trackCount += 1 # If the pressed key is in the keymap if KEY_MAP_PIANO.has_key(key): - # CsoundNote parameters + 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 = 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')) + + instrumentName = self.instrument + print >>log, 'instrumentName:', instrumentName pitch = KEY_MAP_PIANO[key] - duration = -1 - instrument = self.instrument - - if event.state == gtk.gdk.MOD1_MASK: - pitch = pitch+5 - if instrument[ 0: 4 ] == 'drum': - if GenerationConstants.DRUMPITCH.has_key( pitch ): - pitch = GenerationConstants.DRUMPITCH[ pitch ] + if instrumentName in Instrument.DRUM : + print >>log, 'kit_element: ', Config.KIT_ELEMENT[pitch] + playkey(36,100, Instrument.DRUM[instrumentName][ Config.KIT_ELEMENT[pitch] ] ) - if Config.INSTRUMENTS[instrument].kit != None: - instrument = Config.INSTRUMENTS[instrument].kit[pitch].name - pitch = 36 - duration = 100 + else: + if event.state == gtk.gdk.MOD1_MASK: + pitch += 5 - if Config.INSTRUMENTS[instrument].csoundInstrumentId == Config.INST_PERC: #Percussions resonance - duration = 60 + instrument = Instrument.INST[ instrumentName ] + if instrument.csoundInstrumentName == 'inst_perc': #Percussions resonance + playkey( pitch, 60, instrument) + else: + playkey( pitch, -1, 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 = Config.INSTRUMENTS[instrument].instrumentId, - reverbSend = self.reverb, - tied = True, - mode = 'mini') - self.csnd.play(self.key_dict[key], 0.3) - if self.getPlayState(): - recOnset = 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 = Config.INSTRUMENTS[instrument].instrumentId, - reverbSend = self.reverb, - tied = False, - mode = 'mini')) def onKeyRelease(self,widget,event): key = event.hardware_keycode @@ -120,7 +123,7 @@ class KeyboardStandAlone: if KEY_MAP_PIANO.has_key(key): csnote = self.key_dict[key] - if Config.INSTRUMENTSID[ csnote.instrumentId ].csoundInstrumentId == Config.INST_TIED: + if Instrument.INST_byId[ csnote.instrumentId ].csoundInstrumentName == 'inst_tied': csnote.duration = .5 csnote.decay = 0.7 #csnote.amplitude = 1 diff --git a/miniTamTam/Loop.py b/miniTamTam/Loop.py index 4beee57..deb1cad 100755 --- a/miniTamTam/Loop.py +++ b/miniTamTam/Loop.py @@ -6,6 +6,7 @@ from Util.CSoundNote import CSoundNote from Util.CSoundClient import new_csound_client from Util.NoteDB import Note from Util.NoteDB import PARAMETER +from Util import Instrument from Generation.GenerationConstants import GenerationConstants class Loop: @@ -49,10 +50,10 @@ class Loop: pitch = i[1] gain = i[2]*self.volume duration = i[3] - if Config.INSTRUMENTS[instrument].kit != None: + if instrument in Instrument.DRUM: if GenerationConstants.DRUMPITCH.has_key(pitch): pitch = GenerationConstants.DRUMPITCH[pitch] - instrument = Config.INSTRUMENTS[instrument].kit[pitch].name + instrument = Instrument.DRUM[ KIT_ELEMENT[pitch] ].name pitch = 36 return CSoundNote( onset = onset, pitch = pitch, @@ -60,7 +61,7 @@ class Loop: pan = 0.5, duration = duration, trackId = 0, - instrumentId = Config.INSTRUMENTS[instrument].instrumentId, + instrumentId = Instrument.INST[instrument].instrumentId, reverbSend = reverb, tied = False, mode = 'mini') diff --git a/miniTamTam/miniTamTamMain.py b/miniTamTam/miniTamTamMain.py index 3829825..8ab939e 100644 --- a/miniTamTam/miniTamTamMain.py +++ b/miniTamTam/miniTamTamMain.py @@ -34,6 +34,7 @@ from RythmGenerator import * from SynthLab.SynthLabWindow import SynthLabWindow from Util.Trackpad import Trackpad from Util.InstrumentPanel import InstrumentPanel +from Util import Instrument Tooltips = Config.Tooltips @@ -121,7 +122,7 @@ class miniTamTamMain(SubActivity): self.network.connectMessage( Net.HT_TEMPO_UPDATE, self.processHT_TEMPO_UPDATE ) self.network.connectMessage( Net.PR_SYNC_QUERY, self.processPR_SYNC_QUERY ) self.network.connectMessage( Net.PR_TEMPO_QUERY, self.processPR_TEMPO_QUERY ) - self.network.connectMessage( Net.PR_TEMPO_CHANGE, self.processPR_TEMPO_CHANGE ) + self.network.connectMessage( Net.PR_REQUEST_TEMPO_CHANGE, self.processPR_REQUEST_TEMPO_CHANGE ) # data packing classes self.packer = xdrlib.Packer() @@ -139,8 +140,10 @@ class miniTamTamMain(SubActivity): if os.path.isfile("FORCE_SHARE"): # HOST r = random.random() - print "::::: Sharing as TTDBG%f :::::" % r - self.activity.set_title(_gettext("TTDBG%f" % r)) + #print "::::: Sharing as TTDBG%f :::::" % r + #self.activity.set_title(_gettext("TTDBG%f" % r)) + print "::::: Sharing as TamTam :::::" + self.activity.set_title(_gettext("TamTam")) self.activity.connect( "shared", self.shared ) self.activity.share() elif self.activity._shared_activity: # PEER @@ -251,7 +254,9 @@ class miniTamTamMain(SubActivity): self.tempoSliderBoxImgTop = gtk.Image() self.tempoSliderBoxImgTop.set_from_file(Config.IMAGE_ROOT + 'tempo5.png') self.tempoAdjustment = gtk.Adjustment(value=self.tempo, lower=Config.PLAYER_TEMPO_LOWER, upper=Config.PLAYER_TEMPO_UPPER, step_incr=1, page_incr=1, page_size=1) - tempoSlider = ImageVScale( Config.IMAGE_ROOT + "sliderbutvert.png", self.tempoAdjustment, 5) + #tempoSlider = ImageVScale( Config.IMAGE_ROOT + "sliderbutvert.png", self.tempoAdjustment, 5) + tempoSlider = gtk.VScale( self.tempoAdjustment) + #TEMP tempoSlider.set_inverted(True) tempoSlider.set_size_request(15,320) self.tempoAdjustmentHandler = self.tempoAdjustment.connect("value_changed" , self.handleTempoSliderChange) @@ -481,8 +486,7 @@ class miniTamTamMain(SubActivity): def handleTempoSliderChange(self,adj): print "handleTempoSliderChange" if self.network.isPeer(): - pass - #self.requestTempoChange(val) + self.requestTempoChange(int(adj.value)) else: self._updateTempo( int(adj.value), True ) @@ -557,7 +561,7 @@ class miniTamTamMain(SubActivity): #data is drum1kit, drum2kit, or drum3kit #print 'HANDLE: Generate Button' self.rythmInstrument = data - instrumentId = Config.INSTRUMENTS[data].instrumentId + instrumentId = Instrument.INST[data].instrumentId for (o,n) in self.noteList : self.csnd.loopUpdate(n, NoteDB.PARAMETER.INSTRUMENT, instrumentId, -1) self.drumFillin.setInstrument( self.rythmInstrument ) @@ -589,7 +593,7 @@ class miniTamTamMain(SubActivity): pan = 0.5, duration = 20, trackId = 1, - instrumentId = Config.INSTRUMENTS[instrument].instrumentId, + instrumentId = Instrument.INST[instrument].instrumentId, reverbSend = 0, tied = False, mode = 'mini'), @@ -631,11 +635,6 @@ class miniTamTamMain(SubActivity): r = str(random.randrange(1,11)) self.playInstrumentNote('guidice' + r) - def getInstrumentList(self): - cleanInstrumentList = [instrument for instrument in Config.INSTRUMENTS.keys() if instrument[0:4] != 'drum' and instrument[0:3] != 'mic' and instrument[0:3] != 'lab' and instrument[0:4] != 'guid'] - cleanInstrumentList.sort(lambda g,l: cmp(Config.INSTRUMENTS[g].category, Config.INSTRUMENTS[l].category) ) - return cleanInstrumentList + ['drum1kit', 'drum2kit', 'drum3kit'] - def onActivate( self, arg ): self.csnd.loopPause() self.csnd.loopClear() @@ -691,7 +690,10 @@ class miniTamTamMain(SubActivity): def buddy_joined( self, activity, buddy ): print "buddy joined " + str(buddy) - print buddy.props.ip4_address + try: + print buddy.props.ip4_address + except: + print "bad ip4_address" if self.network.isHost(): # TODO how do I figure out if this buddy is me? if buddy.props.ip4_address: @@ -724,8 +726,9 @@ class miniTamTamMain(SubActivity): self.network.send( Net.PR_TEMPO_QUERY ) def requestTempoChange( self, val ): + print "requestTempoChange", val self.packer.pack_int(val) - self.network.sendAll( Net.PR_TEMPO_CHANGE, self.packer.get_buffer() ) + self.network.send( Net.PR_REQUEST_TEMPO_CHANGE, self.packer.get_buffer() ) self.packer.reset() #-- Handlers ----------------------------------------------------------- @@ -753,14 +756,18 @@ class miniTamTamMain(SubActivity): self.syncQueryStart.pop(hash) def processHT_TEMPO_UPDATE( self, sock, message, data ): - #print "got tempo update" + print "got tempo update" self.unpacker.reset(data) - self.tempoAdjustment.signal_handler_block( self.tempoAdjustmentHandler ) + self.tempoAdjustment.handler_block( self.tempoAdjustmentHandler ) val = self.unpacker.unpack_int() + print "a" self.tempoAdjustment.set_value( val ) + time.sleep(0.01) + print "b" self._updateTempo( val ) - self.tempoAdjustment.signal_handler_unblock( self.tempoAdjustmentHandler ) + self.tempoAdjustment.handler_unblock( self.tempoAdjustmentHandler ) self.sendSyncQuery() + print "done" def processPR_SYNC_QUERY( self, sock, message, data ): self.packer.pack_float(self.nextHeartbeat()) @@ -768,15 +775,19 @@ class miniTamTamMain(SubActivity): self.packer.reset() def processPR_TEMPO_QUERY( self, sock, message, data ): + print "processPR_TEMPO_QUERY" self.packer.pack_int(self.tempo) self.network.send( Net.HT_TEMPO_UPDATE, self.packer.get_buffer(), to = sock ) self.packer.reset() + print "done" - def processPR_TEMPO_CHANGE( self, sock, message, data ): - print "got tempo change" + def processPR_REQUEST_TEMPO_CHANGE( self, sock, message, data ): self.unpacker.reset(data) val = self.unpacker.unpack_int() + print "got tempo change", val self.tempoAdjustment.set_value( val ) + time.sleep(0.01) + print "done" #----------------------------------------------------------------------- # Sync @@ -799,6 +810,8 @@ class miniTamTamMain(SubActivity): return self.ticksPerSecond*(delta % self.beatDuration) def updateSync( self ): + #TEMP + return False if self.network.isOffline(): return False elif self.network.isWaiting(): |