From 4754a96b660213b785a09023b4c305fbb24a590d Mon Sep 17 00:00:00 2001 From: amartin Date: Sat, 22 Sep 2007 09:58:06 +0000 Subject: Jam keyboard recording --- diff --git a/TamTamJam.activity/Jam/JamMain.py b/TamTamJam.activity/Jam/JamMain.py index b9641b4..e6418d8 100644 --- a/TamTamJam.activity/Jam/JamMain.py +++ b/TamTamJam.activity/Jam/JamMain.py @@ -519,11 +519,9 @@ class JamMain(gtk.EventBox): def _playLoop( self, id, volume, reverb, tune, loopId = None, force = False, sync = True ): if loopId == None: # create new loop startTick = 0 - firstTime = True else: # update loop startTick = self.csnd.loopGetTick( loopId ) self.csnd.loopDestroy( loopId ) - firstTime = False loopId = self.csnd.loopCreate() @@ -544,25 +542,25 @@ class JamMain(gtk.EventBox): n.cs.onset += offset self.csnd.loopPlay( n, 1, loopId = loopId ) n.popState() + for n in self.noteDB.getNotesByTrack( page, 1 ): # metronome track + self.csnd.loopPlay( n, 1, loopId = loopId ) offset += self.noteDB.getPage(page).ticks self.csnd.loopSetNumTicks( offset, loopId ) - # sync to heartbeat - #if False: # firstTime: # always force first note to play rather than snaping to nearest beat.. good idea? - # startTick = offset - Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) - if sync: - while startTick > offset: # align with last beat - startTick -= Config.TICKS_PER_BEAT - beatTick = int(startTick) % Config.TICKS_PER_BEAT - heartTick = self.csnd.loopGetTick( self.heartbeatLoop ) - if beatTick > heartTick: - if beatTick - heartTick < heartTick + Config.TICKS_PER_BEAT - beatTick: + while startTick > offset: # align with last beat + startTick -= Config.TICKS_PER_BEAT + + if sync: # sync to heartbeat + beatTick = startTick % Config.TICKS_PER_BEAT + syncTick = self.csnd.loopGetTick( self.heartbeatLoop ) + if beatTick > syncTick: + if beatTick - syncTick < syncTick + Config.TICKS_PER_BEAT - beatTick: startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) else: startTick = (1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) else: - if heartTick - beatTick < beatTick + Config.TICKS_PER_BEAT - heartTick: + if syncTick - beatTick < beatTick + Config.TICKS_PER_BEAT - syncTick: startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) else: startTick = (-1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) @@ -571,6 +569,7 @@ class JamMain(gtk.EventBox): startTick -= offset elif startTick < 0: startTick += offset + self.csnd.loopSetTick( startTick, loopId ) if not self.paused or force: @@ -581,11 +580,9 @@ class JamMain(gtk.EventBox): def _stopLoop( self, loopId ): self.csnd.loopDestroy( loopId ) - def playMetronome( self, period ): - if self.metronome: - self.stopMetronome() + def addMetronome( self, page, period ): - self.metronome = self.csnd.loopCreate() + self.noteDB.deleteNotesByTrack( [ page ], [ 1 ] ) baseCS = CSoundNote( 0, # onset 36, # pitch @@ -598,39 +595,30 @@ class JamMain(gtk.EventBox): tied = True, mode = 'mini' ) + stream = [] + offset = 0 - cs = baseCS.clone() - cs.instrumentId = Config.INSTRUMENTS["drum1hatshoulder"].instrumentId - cs.amplitude = 0.5 - - stream = [ cs ] - - onset = period - while onset < Config.TICKS_PER_BEAT: + for b in range( self.noteDB.getPage( page ).beats ): cs = baseCS.clone() - cs.onset = onset - stream.append( cs ) - onset += period - - self.noteDB.addNotes( [ self.metronomePage, 0, len(stream) ] + stream + [ -1 ] ) - - for n in self.noteDB.getNotesByTrack( self.metronomePage, 0 ): - self.csnd.loopPlay( n, 1, loopId = self.metronome ) + cs.instrumentId = Config.INSTRUMENTS["drum1hatshoulder"].instrumentId + cs.amplitude = 0.5 + cs.onset += offset - self.csnd.loopSetNumTicks( Config.TICKS_PER_BEAT, self.metronome ) - self.csnd.loopSetTick( 0, self.metronome ) - - self.csnd.loopStart( self.metronome ) - - def stopMetronome( self ): - if not self.metronome: - return + stream.append( cs ) + + onset = period + while onset < Config.TICKS_PER_BEAT: + cs = baseCS.clone() + cs.onset = onset + offset + stream.append( cs ) + onset += period - self.csnd.loopDestroy( self.metronome ) - self.noteDB.deleteNotesByTrack( [ self.metronomePage ], [ 0 ] ) + offset += Config.TICKS_PER_BEAT - self.metronome = None - + self.noteDB.addNotes( [ page, 1, len(stream) ] + stream + [ -1 ] ) + + def removeMetronome( self, page ): + self.noteDB.deleteNotesByTrack( [ page ], [ 1 ] ) def setPaused( self, paused ): if self.paused == paused: diff --git a/TamTamJam.activity/Jam/Popup.py b/TamTamJam.activity/Jam/Popup.py index ce0204e..7ca17d0 100644 --- a/TamTamJam.activity/Jam/Popup.py +++ b/TamTamJam.activity/Jam/Popup.py @@ -810,7 +810,7 @@ class Loop( Popup ): self.owner.pushInstrument( self.instrument ) self.owner.setKeyboardListener( self ) - self.owner.playMetronome( self.grid ) + self.owner.addMetronome( self.curPage, self.grid ) self.recordLoop = self.owner._playLoop( self.instrument["id"], self.instrument["amplitude"], self.instrument["reverb"], [ self.curPage ], force = True, sync = False ) self.updatePlayhead() self.recordTimeout = gobject.timeout_add( 20, self._record_timeout ) @@ -826,7 +826,7 @@ class Loop( Popup ): if self.recordingNote: self.finishNote() - self.owner.stopMetronome() + self.owner.removeMetronome( self.curPage ) self.owner._stopLoop( self.recordLoop ) self.recordLoop = None self.clearPlayhead() @@ -843,6 +843,7 @@ class Loop( Popup ): onset = self.grid * int( onset/self.grid + 0.5 ) if onset < 0: onset += ticks elif onset >= ticks: onset -= ticks + self.recordingNotePassed = False cs = CSoundNote( onset, pitch, @@ -865,7 +866,7 @@ class Loop( Popup ): self.recordingNote = self.noteDB.addNote( -1, self.curPage, 0, cs ) - self.recordLoop = self.owner._playLoop( self.instrument["id"], self.instrument["amplitude"], self.instrument["reverb"], [ self.curPage ], self.recordLoop, force = True ) + self.recordLoop = self.owner._playLoop( self.instrument["id"], self.instrument["amplitude"], self.instrument["reverb"], [ self.curPage ], self.recordLoop, force = True, sync = False ) def finishNote( self ): self.recordingNote = None @@ -886,7 +887,10 @@ class Loop( Popup ): note = self.noteDB.getNote( self.curPage, 0, self.recordingNote ) - if tick < note.cs.onset: + if tick > note.cs.onset: + self.recordingNotePassed = True + + if self.recordingNotePassed and tick < note.cs.onset: tick = self.noteDB.getPage( self.curPage ).ticks self.noteDB.updateNote( note.page, note.track, note.id, PARAMETER.DURATION, tick - note.cs.onset ) for n in self.noteDB.getNotesByTrack( self.curPage, 0 ): -- cgit v0.9.1