Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/TamTamJam.activity/Jam/JamMain.py
diff options
context:
space:
mode:
authoramartin <olpc@xo-05-28-21.localdomain>2007-09-22 09:58:06 (GMT)
committer amartin <olpc@xo-05-28-21.localdomain>2007-09-22 09:58:06 (GMT)
commit4754a96b660213b785a09023b4c305fbb24a590d (patch)
treed224c7f66595a3bd66037c6284abc9459f1fa7d9 /TamTamJam.activity/Jam/JamMain.py
parent500db320e639d38e1ea0cd851df4f97a7cc3f254 (diff)
Jam keyboard recording
Diffstat (limited to 'TamTamJam.activity/Jam/JamMain.py')
-rw-r--r--TamTamJam.activity/Jam/JamMain.py78
1 files changed, 33 insertions, 45 deletions
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: