diff options
author | Oli <olivier.belanger@umontreal.ca> | 2007-09-24 05:30:48 (GMT) |
---|---|---|
committer | Oli <olivier.belanger@umontreal.ca> | 2007-09-24 05:30:48 (GMT) |
commit | 64ebdb2816d5e70873e717ce028689a100635daa (patch) | |
tree | b89da0c28d36fedb6e83cb8edc69f313c2c15ffc /TamTamJam.activity/Jam | |
parent | 1a3140d1dd8df2db367fd5142c8a586583268835 (diff) | |
parent | 9d40d71e089f6db35c8aee0aa51f3f3b1e4ce87f (diff) |
Merge branch 'master' of git+ssh://olipet@dev.laptop.org/git/projects/tamtam
Diffstat (limited to 'TamTamJam.activity/Jam')
-rw-r--r-- | TamTamJam.activity/Jam/JamMain.py | 82 | ||||
-rw-r--r-- | TamTamJam.activity/Jam/Picker.py | 12 | ||||
-rw-r--r-- | TamTamJam.activity/Jam/Popup.py | 2 | ||||
-rw-r--r-- | TamTamJam.activity/Jam/Toolbars.py | 38 |
4 files changed, 98 insertions, 36 deletions
diff --git a/TamTamJam.activity/Jam/JamMain.py b/TamTamJam.activity/Jam/JamMain.py index e6418d8..1f63ead 100644 --- a/TamTamJam.activity/Jam/JamMain.py +++ b/TamTamJam.activity/Jam/JamMain.py @@ -294,7 +294,8 @@ class JamMain(gtk.EventBox): self.syncQueryStart = {} self.syncTimeout = None self.heartbeatLoop = self.csnd.loopCreate() - self.csnd.loopSetNumTicks( Config.TICKS_PER_BEAT, self.heartbeatLoop ) + self.syncBeats = 4 + self.csnd.loopSetNumTicks( self.syncBeats*Config.TICKS_PER_BEAT, self.heartbeatLoop ) self.heartbeatStart = time.time() self.csnd.loopStart( self.heartbeatLoop ) @@ -445,15 +446,14 @@ class JamMain(gtk.EventBox): def popInstrument( self ): self.instrument = self.instrumentStack.pop() - def _playDrum( self, id, pageId, volume, reverb, beats, regularity, loopId = None ): + def _playDrum( self, id, pageId, volume, reverb, beats, regularity, loopId = None, sync = True ): if loopId == None: # create new loop - startTick = 0 - firstTime = True + if sync: startTick = self.csnd.loopGetTick( self.heartbeatLoop ) + else: startTick = 0 else: # update loop startTick = self.csnd.loopGetTick( loopId ) self.csnd.loopDestroy( loopId ) - firstTime = False loopId = self.csnd.loopCreate() @@ -481,24 +481,23 @@ class JamMain(gtk.EventBox): self.drumFillin.play() + while startTick > ticks: + startTick -= ticks + # sync to heartbeat - if False: # firstTime: # always force first note to play rather than snaping to nearest beat.. good idea? - startTick = ticks - Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) - else: - while startTick > ticks: # align with last beat - startTick -= Config.TICKS_PER_BEAT + if sync: 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: - startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) + syncTick = self.csnd.loopGetTick( self.heartbeatLoop ) % Config.TICKS_PER_BEAT + if beatTick > syncTick: + if beatTick - syncTick < syncTick + Config.TICKS_PER_BEAT - beatTick: + startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick else: - startTick = (1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) + startTick = (1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick else: - if heartTick - beatTick < beatTick + Config.TICKS_PER_BEAT - heartTick: - startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) + if syncTick - beatTick < beatTick + Config.TICKS_PER_BEAT - syncTick: + startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick else: - startTick = (-1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) + startTick = (-1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick if startTick >= ticks: startTick -= ticks @@ -518,7 +517,8 @@ 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 + if sync: startTick = self.csnd.loopGetTick( self.heartbeatLoop ) + else: startTick = 0 else: # update loop startTick = self.csnd.loopGetTick( loopId ) self.csnd.loopDestroy( loopId ) @@ -548,22 +548,23 @@ class JamMain(gtk.EventBox): self.csnd.loopSetNumTicks( offset, loopId ) - while startTick > offset: # align with last beat - startTick -= Config.TICKS_PER_BEAT - - if sync: # sync to heartbeat + while startTick > offset: + startTick -= offset + + # sync to heartbeat + if sync: beatTick = startTick % Config.TICKS_PER_BEAT - syncTick = self.csnd.loopGetTick( self.heartbeatLoop ) + syncTick = self.csnd.loopGetTick( self.heartbeatLoop ) % Config.TICKS_PER_BEAT 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 ) + startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick else: - startTick = (1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) + startTick = (1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick else: 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 ) + startTick = (int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick else: - startTick = (-1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + self.csnd.loopGetTick( self.heartbeatLoop ) + startTick = (-1 + int(startTick)//Config.TICKS_PER_BEAT)*Config.TICKS_PER_BEAT + syncTick if startTick >= offset: startTick -= offset @@ -581,7 +582,6 @@ class JamMain(gtk.EventBox): self.csnd.loopDestroy( loopId ) def addMetronome( self, page, period ): - self.noteDB.deleteNotesByTrack( [ page ], [ 1 ] ) baseCS = CSoundNote( 0, # onset @@ -926,6 +926,7 @@ class JamMain(gtk.EventBox): self.noteDB.dumpToStream( stream, True ) self.desktop.dumpToStream( stream ) + stream.sync_beats( self.syncBeats ) scratch.close() except IOError, (errno, strerror): @@ -1092,6 +1093,27 @@ class JamMain(gtk.EventBox): #========================================================== # Sync + def setSyncBeats( self, beats ): + self.jamToolbar.setSyncBeats( beats ) + + def _setSyncBeats( self, beats ): + if beats == self.syncBeats: + return + + self.syncBeats = beats + + ticks = beats * Config.TICKS_PER_BEAT + + curTick = self.csnd.loopGetTick( self.heartbeatLoop ) + + self.csnd.loopSetNumTicks( ticks, self.heartbeatLoop ) + while curTick > ticks: + curTick -= ticks + + self.csnd.loopSetTick( self.heartbeatLoop ) + + self.updateSync() + def nextHeartbeat( self ): delta = time.time() - self.heartbeatStart return self.beatDuration - (delta % self.beatDuration) @@ -1121,7 +1143,7 @@ class JamMain(gtk.EventBox): return True def correctSync( self ): - curTick = self.csnd.loopGetTick( self.heartbeatLoop ) + curTick = self.csnd.loopGetTick( self.heartbeatLoop ) % Config.TICKS_PER_BEAT curTicksIn = curTick % Config.TICKS_PER_BEAT ticksIn = self.heartbeatElapsedTicks() err = curTicksIn - ticksIn diff --git a/TamTamJam.activity/Jam/Picker.py b/TamTamJam.activity/Jam/Picker.py index 167904c..5609e56 100644 --- a/TamTamJam.activity/Jam/Picker.py +++ b/TamTamJam.activity/Jam/Picker.py @@ -34,7 +34,11 @@ class Picker( gtk.HBox ): self.desktop = owner.getDesktop() - self.scrollLeft = gtk.Button( "<" ) + self.scrollLeftImg = gtk.Image() + self.scrollLeftImg.set_from_icon_name('go-left', gtk.ICON_SIZE_BUTTON) + self.scrollLeft = gtk.Button( label = None ) + self.scrollLeft.set_relief(gtk.RELIEF_NONE) + self.scrollLeft.set_image(self.scrollLeftImg) self.scrollLeft.connect( "clicked", self.doScroll, "left" ) self.pack_start( self.scrollLeft, False, False ) @@ -45,7 +49,11 @@ class Picker( gtk.HBox ): self.hadjustment.connect( "changed", self.scrollChanged ) self.hadjustment.connect( "value-changed", self.scrollChanged ) - self.scrollRight = gtk.Button( ">" ) + self.scrollRightImg = gtk.Image() + self.scrollRightImg.set_from_icon_name('go-right', gtk.ICON_SIZE_BUTTON) + self.scrollRight = gtk.Button( label = None ) + self.scrollRight.set_relief(gtk.RELIEF_NONE) + self.scrollRight.set_image(self.scrollRightImg) self.scrollRight.connect( "clicked", self.doScroll, "right" ) self.pack_start( self.scrollRight, False, False ) diff --git a/TamTamJam.activity/Jam/Popup.py b/TamTamJam.activity/Jam/Popup.py index 7ca17d0..9268870 100644 --- a/TamTamJam.activity/Jam/Popup.py +++ b/TamTamJam.activity/Jam/Popup.py @@ -910,7 +910,7 @@ class Loop( Popup ): self.noteDB.deleteNote( n.page, n.track, n.id ) else: break - 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 _record_timeout( self ): self.updatePlayhead() diff --git a/TamTamJam.activity/Jam/Toolbars.py b/TamTamJam.activity/Jam/Toolbars.py index 30001ef..e3b255d 100644 --- a/TamTamJam.activity/Jam/Toolbars.py +++ b/TamTamJam.activity/Jam/Toolbars.py @@ -7,6 +7,8 @@ from gettext import gettext as _ from sugar.graphics.palette import Palette, WidgetInvoker from sugar.graphics.radiotoolbutton import RadioToolButton +from sugar.graphics.combobox import ComboBox +from sugar.graphics.toolcombobox import ToolComboBox import common.Config as Config @@ -25,7 +27,7 @@ class JamToolbar( gtk.Toolbar ): self.volumeAdjustment = gtk.Adjustment( 0.0, 0, 1.0, 0.1, 0.1, 0 ) self.volumeAdjustment.connect( 'value-changed', self.handleVolume ) self.volumeSlider = gtk.HScale( adjustment = self.volumeAdjustment ) - self.volumeSlider.set_size_request( 450, -1 ) + self.volumeSlider.set_size_request( 300, -1 ) self.volumeSlider.set_draw_value( False ) self._add_tooltip( self.volumeSlider, _("Master Volume") ) self._insert_widget( self.volumeSlider, -1 ) @@ -38,12 +40,37 @@ class JamToolbar( gtk.Toolbar ): self.tempoAdjustment = gtk.Adjustment( Config.PLAYER_TEMPO_LOWER, Config.PLAYER_TEMPO_LOWER, Config.PLAYER_TEMPO_UPPER+1, 10, 10, 0 ) self.tempoAdjustment.connect( 'value-changed', self.handleTempo ) self.tempoSlider = gtk.HScale( adjustment = self.tempoAdjustment ) - self.tempoSlider.set_size_request( 450, -1 ) + self.tempoSlider.set_size_request( 300, -1 ) self.tempoSlider.set_draw_value( False ) self._add_tooltip( self.tempoSlider, _("Tempo") ) self._insert_widget( self.tempoSlider, -1 ) self._insert_widget( self.tempoImg, -1 ) + self._insert_separator( True ) + + label = gtk.Label( _("Sync to:") ) + self.syncLabel = gtk.ToolItem() + self.syncLabel.add( label ) + self.insert( self.syncLabel, -1 ) + + self.comboBox = ComboBox() + self.comboBox.append_item( 1, _("1 Beat") ) + self.comboBox.append_item( 2, _("2 Beats") ) + self.comboBox.append_item( 3, _("3 Beats") ) + self.comboBox.append_item( 4, _("4 Beats") ) + self.comboBox.append_item( 5, _("5 Beats") ) + self.comboBox.append_item( 6, _("6 Beats") ) + self.comboBox.append_item( 7, _("7 Beats") ) + self.comboBox.append_item( 8, _("8 Beats") ) + self.comboBox.append_item( 9, _("9 Beats") ) + self.comboBox.append_item( 10, _("10 Beats") ) + self.comboBox.append_item( 11, _("11 Beats") ) + self.comboBox.append_item( 12, _("12 Beats") ) + self.comboBox.set_active( 4 - 1 ) # default 4 beats + self.comboBox.connect( "changed", self.changeSync ) + self.syncBox = ToolComboBox( self.comboBox ) + self.insert( self.syncBox, -1 ) + self.show_all() #def _add_palette( self, widget, palette, position = Palette.DEFAULT ): @@ -67,6 +94,12 @@ class JamToolbar( gtk.Toolbar ): separator.set_expand( expand ) self.insert( separator, -1 ) + def setSyncBeats( self, beats ): + self.comboBox.set_active( beats - 1 ) + + def changeSync( self, widget ): + self.owner._setSyncBeats( widget.get_active() + 1 ) + def mapRange( self, value, ilower, iupper, olower, oupper ): if value == iupper: return oupper @@ -126,4 +159,3 @@ class DesktopToolbar( gtk.Toolbar ): def setDesktop( self, widget, which ): if widget.get_active(): self.owner._setDesktop( which ) - |