From 6f57fcb7286d28d3d483c1f8ce7d3ee6f439a52b Mon Sep 17 00:00:00 2001 From: amartin Date: Mon, 27 Aug 2007 09:11:28 +0000 Subject: Jam loops --- (limited to 'Jam') diff --git a/Jam/Block.py b/Jam/Block.py index c86a53b..adc487a 100644 --- a/Jam/Block.py +++ b/Jam/Block.py @@ -135,6 +135,9 @@ class Block(): self.active = state self.invalidate_rect( not self.dragging ) + if self.child: + self.child.setActive( state ) + def button_press( self, event ): if event.y < self.y or event.y > self.endY: @@ -411,6 +414,17 @@ class Loop(Block): def _doButtonPress( self, event ): # we were hit with a button press pass + def button_release( self, event ): + if not self.dragging: + if self.active: + root = self.getRoot() + self.owner.deactivateLoop( root.child ) + else: + root = self.getRoot() + if root.type == Instrument: # must be attached to an instrument + self.owner.activateLoop( root.child ) + Block.button_release( self, event ) + def _doDraw( self, startX, startY, stopX, stopY, pixmap ): y = max( startY, self.y ) endY = min( stopY, self.endY ) diff --git a/Jam/Desktop.py b/Jam/Desktop.py index 1a99cee..11d835f 100644 --- a/Jam/Desktop.py +++ b/Jam/Desktop.py @@ -33,6 +33,8 @@ class Desktop( gtk.EventBox ): self.activeInstrument = None self.activeDrum = None + self.loops = {} # dict of playing loops by loop root + self.add_events(gtk.gdk.POINTER_MOTION_MASK|gtk.gdk.POINTER_MOTION_HINT_MASK) self.connect( "size-allocate", self.size_allocate ) @@ -156,6 +158,27 @@ class Desktop( gtk.EventBox ): data = self.activeDrum.data self.owner._playDrum( data["id"], data["volume"], data["beats"], data["regularity"], data["seed"] ) + def activateLoop( self, block ): + block.setActive( True ) + + inst = block.parent.data + + tune = [] + itr = block + while itr != None: + tune.append( itr.data["id"] ) + itr = itr.child + + loopId = self.owner._playLoop( inst["id"], inst["volume"], tune ) + + self.loops[block] = loopId + + def deactivateLoop( self, block ): + block.setActive( False ) + + self.owner._stopLoop( self.loops[block] ) + del self.loops[block] + #========================================================== # Mouse diff --git a/Jam/JamMain.py b/Jam/JamMain.py index 9ef3fc3..28e19f6 100644 --- a/Jam/JamMain.py +++ b/Jam/JamMain.py @@ -71,12 +71,12 @@ class JamMain(SubActivity): #"Picker_Bg": colormap.alloc_color( style.COLOR_TOOLBAR_GREY.get_html() ), #"Picker_Bg_Inactive": colormap.alloc_color( style.COLOR_BUTTON_GREY.get_html() ), "Picker_Fg": colormap.alloc_color( style.COLOR_WHITE.get_html() ), - "Border_Active": colormap.alloc_color( "#FF6000" ), + "Border_Active": colormap.alloc_color( "#590000" ), "Border_Inactive": colormap.alloc_color( "#8D8D8D" ), "Border_Highlight": colormap.alloc_color( "#FFFFFF" ), - "Bg_Active": colormap.alloc_color( "#9400BE" ), + "Bg_Active": colormap.alloc_color( "#FFDDEA" ), "Bg_Inactive": colormap.alloc_color( "#DBDBDB" ), - "Note_Fill_Active": lighten( colormap, "#FF6000" ), # base "Border_Active" + "Note_Fill_Active": lighten( colormap, "#590000" ), # base "Border_Active" "Note_Fill_Inactive": lighten( colormap, "#8D8D8D" ) } # base "Border_Inactive" self.colors[ "Note_Border_Active"] = self.colors["Border_Active"] self.colors[ "Note_Border_Inactive"] = self.colors["Border_Inactive"] @@ -306,7 +306,6 @@ class JamMain(SubActivity): "pan": 0.5, "reverb": self.reverb } - def _playDrum( self, id, volume, beats, regularity, seed ): def flatten(ll): rval = [] @@ -340,6 +339,36 @@ class JamMain(SubActivity): self.drumFillin.stop() self.csnd.loopPause() + def _playLoop( self, id, volume, tune ): + loopId = self.csnd.loopCreate() + + offset = 0 + print "------------", loopId, tune + temp = [] + for page in tune: + for n in self.noteDB.getNotesByTrack( page, 0 ): + temp.append( n ) + n.pushState() + n.cs.instrumentId = id + n.cs.onset += offset + self.csnd.loopPlay( n, 1, loopId = loopId ) + n.popState() + offset += self.noteDB.getPage(page).ticks + + print temp + + self.csnd.loopSetNumTicks( offset, loopId ) + + # TODO update for beat syncing + + self.csnd.loopStart( loopId ) + + return loopId + + def _stopLoop( self, loopId ): + print "===============", loopId + self.csnd.loopDestroy( loopId ) + #========================================================== # Get/Set -- cgit v0.9.1