Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Jam
diff options
context:
space:
mode:
authoramartin <olpc@xo-05-28-21.localdomain>2007-08-27 12:34:58 (GMT)
committer amartin <olpc@xo-05-28-21.localdomain>2007-08-27 12:34:58 (GMT)
commit66de29ff7807cbc2d0849ece71146fc9e72e1fe4 (patch)
treee689472523fe3a86909ec401e07c95fd0df789a0 /Jam
parent6f57fcb7286d28d3d483c1f8ce7d3ee6f439a52b (diff)
Jam loops
Diffstat (limited to 'Jam')
-rw-r--r--Jam/Block.py60
-rw-r--r--Jam/Desktop.py18
-rw-r--r--Jam/JamMain.py18
-rw-r--r--Jam/Picker.py11
4 files changed, 95 insertions, 12 deletions
diff --git a/Jam/Block.py b/Jam/Block.py
index adc487a..5695987 100644
--- a/Jam/Block.py
+++ b/Jam/Block.py
@@ -49,6 +49,11 @@ class Block():
self.active = False
+ def dumpToStream( self, ostream, child = False ):
+ ostream.block_add( ClassToStr[ self.type ], self.x, self.y, child, self.data )
+ if self.child:
+ self.child.dumpToStream( ostream, True )
+
def destroy( self ):
if self.child:
self.child.destroy()
@@ -135,9 +140,6 @@ 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:
@@ -322,6 +324,7 @@ class Drum(Block):
def substitute( self, block ):
+ self.data["name"] = block.data["name"]
self.data["id"] = block.data["id"]
self.img = [ self.owner.getInstrumentImage( self.data["id"], False ),
@@ -407,9 +410,48 @@ class Loop(Block):
self.parentOffset = Loop.HEAD - 4
+ def substitute( self, block ):
+ self.data["id"] = block.data["id"]
+
+ self.img = [ self.owner.getInstrumentImage( self.data["id"], False ),
+ self.owner.getInstrumentImage( self.data["id"], True ) ]
+
+ self.invalidate_rect( True )
+
+ if self.active:
+ self.owner.updateDrum()
+
def getWidth( self ):
beats = self.owner.noteDB.getPage(self.data["id"]).beats
return Loop.WIDTH[beats]
+
+ def setActive( self, state ):
+ Block.setActive( self, state )
+
+ if self.child:
+ self.child.setActive( state )
+
+ def addChild( self, child ):
+ Block.addChild( self, child )
+ if self.active:
+ child.setActive( True )
+ self.owner.updateLoop( self.getRoot().child )
+
+ def _removeParent( self ):
+ if self.active:
+ loopRoot = self.getRoot().child
+ parent = self.parent
+ else:
+ loopRoot = None
+
+ Block._removeParent( self )
+
+ if loopRoot == self:
+ self.owner.deactivateLoop( loopRoot )
+ elif loopRoot != None:
+ self.setActive( False )
+ parent.child = None # disconnect us before updating
+ self.owner.updateLoop( loopRoot )
def _doButtonPress( self, event ): # we were hit with a button press
pass
@@ -539,4 +581,14 @@ class Loop(Block):
self.gc.set_clip_origin( x-Loop.MASK_TAIL, self.y )
pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.TAIL, self.height )
-
+StrToClass = {
+ "Instrument": Instrument,
+ "Drum": Drum,
+ "Loop": Loop
+ }
+
+ClassToStr = {
+ Instrument: "Instrument",
+ Drum: "Drum",
+ Loop: "Loop"
+ }
diff --git a/Jam/Desktop.py b/Jam/Desktop.py
index 11d835f..40b5675 100644
--- a/Jam/Desktop.py
+++ b/Jam/Desktop.py
@@ -49,6 +49,9 @@ class Desktop( gtk.EventBox ):
self.dragging = False
self.possibleDelete = False
+ def dumpToStream( self, ostream ):
+ for b in self.blocks:
+ block.dumpToStream( ostream )
def size_allocate( self, widget, allocation ):
if self.screenBuf == None or self.alloc.width != allocation.width or self.alloc.height != allocation.height:
@@ -169,9 +172,7 @@ class Desktop( gtk.EventBox ):
tune.append( itr.data["id"] )
itr = itr.child
- loopId = self.owner._playLoop( inst["id"], inst["volume"], tune )
-
- self.loops[block] = loopId
+ self.loops[block] = self.owner._playLoop( inst["id"], inst["volume"], tune )
def deactivateLoop( self, block ):
block.setActive( False )
@@ -179,6 +180,17 @@ class Desktop( gtk.EventBox ):
self.owner._stopLoop( self.loops[block] )
del self.loops[block]
+ def updateLoop( self, block ):
+ inst = block.parent.data
+
+ tune = []
+ itr = block
+ while itr != None:
+ tune.append( itr.data["id"] )
+ itr = itr.child
+
+ self.loops[block] = self.owner._playLoop( inst["id"], inst["volume"], tune, self.loops[block] )
+
#==========================================================
# Mouse
diff --git a/Jam/JamMain.py b/Jam/JamMain.py
index 28e19f6..5763ffa 100644
--- a/Jam/JamMain.py
+++ b/Jam/JamMain.py
@@ -43,7 +43,7 @@ class JamMain(SubActivity):
self.reverb = 0
self.csnd = new_csound_client()
- for i in range(1,9):
+ for i in range(0,9):
self.csnd.setTrackVolume( 100, i )
self.csnd.setMasterVolume( self.volume )
self.csnd.setTempo( self.tempo )
@@ -339,8 +339,14 @@ class JamMain(SubActivity):
self.drumFillin.stop()
self.csnd.loopPause()
- def _playLoop( self, id, volume, tune ):
- loopId = self.csnd.loopCreate()
+ def _playLoop( self, id, volume, tune, loopId = None ):
+ if loopId == None: # create new loop
+ loopId = self.csnd.loopCreate()
+ startTick = 0
+ else: # update loop
+ startTick = self.csnd.loopGetTick( loopId )
+ self.csnd.loopDestroy( loopId )
+ loopId = self.csnd.loopCreate()
offset = 0
print "------------", loopId, tune
@@ -359,6 +365,11 @@ class JamMain(SubActivity):
self.csnd.loopSetNumTicks( offset, loopId )
+ while startTick > offset: # align with last beat
+ startTick -= Config.TICK_PER_BEAT
+
+ self.csnd.loopSetTick( startTick, loopId )
+
# TODO update for beat syncing
self.csnd.loopStart( loopId )
@@ -366,7 +377,6 @@ class JamMain(SubActivity):
return loopId
def _stopLoop( self, loopId ):
- print "===============", loopId
self.csnd.loopDestroy( loopId )
#==========================================================
diff --git a/Jam/Picker.py b/Jam/Picker.py
index 52c948f..cfff3e6 100644
--- a/Jam/Picker.py
+++ b/Jam/Picker.py
@@ -406,6 +406,15 @@ class Loop( Picker ):
walloc = widget.get_allocation()
salloc = self.scrolledWindow.get_allocation()
loc = ( walloc.x + salloc.x + event.x - self.hadjustment.get_value(), -1 )
- self.desktop.addBlock( Block.Loop, widget.data, loc, True )
+
+ data = {}
+ for key in widget.data.keys():
+ data[key] = widget.data[key]
+
+ newid = self.owner.noteDB.duplicatePages( [ data["id"] ] )[data["id"]]
+ data["id"] = newid
+
+ self.owner.updateLoopImage( data["id"] )
+ self.desktop.addBlock( Block.Loop, data, loc, True )