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-08 07:04:24 (GMT)
committer amartin <olpc@xo-05-28-21.localdomain>2007-08-08 07:04:24 (GMT)
commitfbd47da49acd5d08f6a44e457f1e648769f06d7a (patch)
tree08724808155904724471e550c96fe6b70b05184e /Jam
parent95ad802c9bb41b7f5165346ccd683f2617482147 (diff)
Jam drawing
Diffstat (limited to 'Jam')
-rw-r--r--Jam/Block.py254
-rw-r--r--Jam/Desktop.py50
-rw-r--r--Jam/JamMain.py39
-rw-r--r--Jam/Picker.py123
4 files changed, 383 insertions, 83 deletions
diff --git a/Jam/Block.py b/Jam/Block.py
index 907ed3d..d2b30a8 100644
--- a/Jam/Block.py
+++ b/Jam/Block.py
@@ -5,35 +5,39 @@ import gtk
import Config
-import random
-
+#::: NOTE:
+# All the graphics resources are loaded in Desktop and referenced here as necessary
+#:::
+
class Block():
WIDTH = 100
HEIGHT = 100
- WIDTH_DIV2 = WIDTH//2
- HEIGHT_DIV2 = HEIGHT//2
-
- def __init__( self, owner, graphics_context ):
+ def __init__( self, owner, graphics_context, data ):
self.owner = owner
self.gc = graphics_context
+ self.data = data
self.type = Block
+ self.width = Block.WIDTH
+ self.height = Block.HEIGHT
+
self.parent = None
self.canChild = False
self.child = None
self.canParent = False
+ self.parentOffest = 0
+
self.dragging = False
self.placed = False
self.x = -1
self.y = -1
- # TEMP
- self.color = random.choice( [ "tempBlock1", "tempBlock2", "tempBlock3", "tempBlock4", "tempBlock5" ] )
+ self.active = True
def destroy( self ):
if self.child:
@@ -53,13 +57,19 @@ class Block():
self.x = x
self.y = y
- self.endX = x + self.type.WIDTH
- self.endY = y + self.type.HEIGHT
+ self.endX = x + self.width
+ self.endY = y + self.height
self.invalidate_rect( not self.dragging )
if self.child:
- self.child.setLoc( self.endX, y )
+ self.child._updateParentLoc( self.endX, y )
+
+ def getAttachLoc( self ):
+ return ( self.x + self.parentOffset, self.y )
+
+ def _updateParentLoc( self, x, y ):
+ self.setLoc( x - self.parentOffset, y )
def testChild( self, loc ):
@@ -67,8 +77,7 @@ class Block():
return False
if self.child:
- handled = self.child.testChild( loc )
- if handled: return handled
+ return self.child.testChild( loc )
elif abs( self.endX - loc[0] ) < 10 and abs( self.y - loc[1] ) < 10:
return self
@@ -77,7 +86,7 @@ class Block():
def addChild( self, child ):
self.child = child
child._addParent( self )
- child.setLoc( self.endX, self.y )
+ child._updateParentLoc( self.endX, self.y )
def removeChild( self ):
self.child._removeParent()
@@ -105,12 +114,11 @@ class Block():
if event.x < self.x:
return False
- if self.child:
- handled = self.child._button_pressB( event )
- if handled: return handled
-
if event.x > self.endX:
- return False
+ if self.child:
+ return self.child._button_pressB( event )
+ else:
+ return False
self.dragOffset = ( event.x - self.x, event.y - self.y )
@@ -143,7 +151,7 @@ class Block():
def _beginDrag( self ):
self.dragging = True
- self.dragOffset = ( self.type.WIDTH_DIV2, self.type.HEIGHT_DIV2 )
+ self.dragOffset = ( self.width//2, self.height//2 )
def invalidateBranch( self, base = True ):
self.invalidate_rect( base )
@@ -151,7 +159,7 @@ class Block():
self.child.invalidateBranch( base )
def invalidate_rect( self, base = True ):
- self.owner.invalidate_rect( self.x, self.y, self.type.WIDTH, self.type.HEIGHT, base )
+ self.owner.invalidate_rect( self.x, self.y, self.width, self.height, base )
def draw( self, startX, startY, stopX, stopY, pixmap ):
if stopY < self.y or startY > self.endY:
@@ -175,33 +183,207 @@ class Block():
return True
def _doDraw( self, startX, startY, stopX, stopY, pixmap ):
- # TEMP
- self.gc.foreground = self.owner.colors[self.color]
- pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.type.WIDTH, self.type.HEIGHT )
pass # override in subclasses
def drawHighlight( self, startX, startY, stopX, stopY, pixmap ):
- # TEMP
- self.gc.foreground = self.owner.colors["tempWhite"]
- pixmap.draw_rectangle( self.gc, False, self.x, self.y, self.type.WIDTH-1, self.type.HEIGHT-1 )
-
+ pass # override in subclasses
class Instrument(Block):
- WIDTH = Block.WIDTH
- HEIGHT = Block.HEIGHT
+ MASK_START = 0
- WIDTH_DIV2 = WIDTH//2
- HEIGHT_DIV2 = HEIGHT//2
-
- def __init__( self, owner, graphics_context ):
- Block.__init__( self, owner, graphics_context )
+ #::: data format:
+ # { }
+ #:::
+ def __init__( self, owner, graphics_context, data ):
+ Block.__init__( self, owner, graphics_context, data )
self.type = Instrument
self.canParent = True
+
+ def _doButtonPress( self, event ): # we were hit with a button press
+ pass
+
+ def _doDraw( self, startX, startY, stopX, stopY, pixmap ):
+ # draw border
+ if self.active: self.gc.foreground = self.owner.colors["Border_Active"]
+ else: self.gc.foreground = self.owner.colors["Border_Inactive"]
+ self.gc.set_clip_origin( self.x-Instrument.MASK_START, self.y )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height )
+
+ # draw block
+ if self.active: self.gc.foreground = self.owner.colors["Bg_Active"]
+ else: self.gc.foreground = self.owner.colors["Bg_Inactive"]
+ self.gc.set_clip_origin( self.x-Instrument.MASK_START, self.y-self.height )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height )
+
+ def drawHighlight( self, startX, startY, stopX, stopY, pixmap ):
+ self.gc.foreground = self.owner.colors["Border_Highlight"]
+ self.gc.set_clip_origin( self.x-Instrument.MASK_START, self.y )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height )
+
+
+class Drum(Block):
+
+ MASK_START = 100
+
+ #::: data format:
+ # { }
+ #:::
+ def __init__( self, owner, graphics_context, data ):
+ Block.__init__( self, owner, graphics_context, data )
+
+ self.type = Drum
+
+ def _doButtonPress( self, event ): # we were hit with a button press
+ pass
+
+ def _doDraw( self, startX, startY, stopX, stopY, pixmap ):
+ # draw border
+ if self.active: self.gc.foreground = self.owner.colors["Border_Active"]
+ else: self.gc.foreground = self.owner.colors["Border_Inactive"]
+ self.gc.set_clip_origin( self.x-Drum.MASK_START, self.y )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height )
+
+ # draw block
+ if self.active: self.gc.foreground = self.owner.colors["Bg_Active"]
+ else: self.gc.foreground = self.owner.colors["Bg_Inactive"]
+ self.gc.set_clip_origin( self.x-Drum.MASK_START, self.y-self.height )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height )
+
+ def drawHighlight( self, startX, startY, stopX, stopY, pixmap ):
+ self.gc.foreground = self.owner.colors["Border_Highlight"]
+ self.gc.set_clip_origin( self.x-Drum.MASK_START, self.y )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, self.width, self.height )
+
+
+class Loop(Block):
+
+ HEAD = 13
+ BEAT = 23
+ TAIL = BEAT + 4
+
+ BEAT_MUL3 = BEAT*3
+
+ MASK_START = 200
+ MASK_BEAT = MASK_START + HEAD
+ MASK_TAIL = MASK_START + HEAD + BEAT*3
+
+ #::: data format:
+ # { "beats": N }
+ #:::
+ def __init__( self, owner, graphics_context, data ):
+ Block.__init__( self, owner, graphics_context, data )
+
+ self.type = Loop
+
+ self.width = Loop.HEAD + Loop.BEAT*(data["beats"]-1) + Loop.TAIL
+
+ self.canParent = True
self.canChild = True
+ self.parentOffset = Loop.HEAD - 4
+
def _doButtonPress( self, event ): # we were hit with a button press
pass
-
+
+ def _doDraw( self, startX, startY, stopX, stopY, pixmap ):
+
+ #-- draw head -----------------------------------------
+
+ # draw border
+ if self.active: self.gc.foreground = self.owner.colors["Border_Active"]
+ else: self.gc.foreground = self.owner.colors["Border_Inactive"]
+ self.gc.set_clip_origin( self.x-Loop.MASK_START, self.y )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, Loop.HEAD, self.height )
+
+ # draw block
+ if self.active: self.gc.foreground = self.owner.colors["Bg_Active"]
+ else: self.gc.foreground = self.owner.colors["Bg_Inactive"]
+ self.gc.set_clip_origin( self.x-Loop.MASK_START, self.y-self.height )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, Loop.HEAD, self.height )
+
+ #-- draw beats ----------------------------------------
+
+ beats = self.data["beats"] - 1 # last beat is drawn with the tail
+ x = self.x + Loop.HEAD
+ while beats > 3:
+ # draw border
+ if self.active: self.gc.foreground = self.owner.colors["Border_Active"]
+ else: self.gc.foreground = self.owner.colors["Border_Inactive"]
+ self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.BEAT_MUL3, self.height )
+
+ # draw block
+ if self.active: self.gc.foreground = self.owner.colors["Bg_Active"]
+ else: self.gc.foreground = self.owner.colors["Bg_Inactive"]
+ self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y-self.height )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.BEAT_MUL3, self.height )
+
+ x += Loop.BEAT_MUL3
+ beats -= 3
+ if beats:
+ width = Loop.BEAT*beats
+
+ # draw border
+ if self.active: self.gc.foreground = self.owner.colors["Border_Active"]
+ else: self.gc.foreground = self.owner.colors["Border_Inactive"]
+ self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, width, self.height )
+
+ # draw block
+ if self.active: self.gc.foreground = self.owner.colors["Bg_Active"]
+ else: self.gc.foreground = self.owner.colors["Bg_Inactive"]
+ self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y-self.height )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, width, self.height )
+
+ x += width
+
+ #-- draw tail -----------------------------------------
+
+ # draw border
+ if self.active: self.gc.foreground = self.owner.colors["Border_Active"]
+ else: self.gc.foreground = self.owner.colors["Border_Inactive"]
+ self.gc.set_clip_origin( x-Loop.MASK_TAIL, self.y )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.TAIL, self.height )
+
+ # draw block
+ if self.active: self.gc.foreground = self.owner.colors["Bg_Active"]
+ else: self.gc.foreground = self.owner.colors["Bg_Inactive"]
+ self.gc.set_clip_origin( x-Loop.MASK_TAIL, self.y-self.height )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.TAIL, self.height )
+
+ def drawHighlight( self, startX, startY, stopX, stopY, pixmap ):
+
+ self.gc.foreground = self.owner.colors["Border_Highlight"]
+
+ #-- draw head -----------------------------------------
+
+ self.gc.set_clip_origin( self.x-Loop.MASK_START, self.y )
+ pixmap.draw_rectangle( self.gc, True, self.x, self.y, Loop.HEAD, self.height )
+
+ #-- draw beats ----------------------------------------
+
+ beats = self.data["beats"] - 1 # last beat is drawn with the tail
+ x = self.x + Loop.HEAD
+ while beats > 3:
+ self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.BEAT_MUL3, self.height )
+
+ x += Loop.BEAT_MUL3
+ beats -= 3
+ if beats:
+ width = Loop.BEAT*beats
+
+ self.gc.set_clip_origin( x-Loop.MASK_BEAT, self.y )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, width, self.height )
+
+ x += width
+
+ #-- draw tail -----------------------------------------
+
+ self.gc.set_clip_origin( x-Loop.MASK_TAIL, self.y )
+ pixmap.draw_rectangle( self.gc, True, x, self.y, Loop.TAIL, self.height )
+
+
diff --git a/Jam/Desktop.py b/Jam/Desktop.py
index 89c890b..4b5f7c4 100644
--- a/Jam/Desktop.py
+++ b/Jam/Desktop.py
@@ -20,7 +20,12 @@ class Desktop( gtk.EventBox ):
win = gtk.gdk.get_default_root_window()
self.gc = gtk.gdk.GC( win )
colormap = self.drawingArea.get_colormap()
- self.colors = { "bg": colormap.alloc_color( Config.BG_COLOR, True, True ), \
+ self.colors = { "bg": colormap.alloc_color( Config.BG_COLOR, True, True ), \
+ "Border_Active": colormap.alloc_color( "#FF6000", True, True ), \
+ "Border_Inactive": colormap.alloc_color( "#5D5D5D", True, True ), \
+ "Border_Highlight": colormap.alloc_color( "#FFFFFF", True, True ), \
+ "Bg_Active": colormap.alloc_color( "#9400BE", True, True ), \
+ "Bg_Inactive": colormap.alloc_color( "#DBDBDB", True, True ), \
"tempWhite": colormap.alloc_color( "#FFFFFF", True, True ), \
"tempBlock1": colormap.alloc_color( "#227733", True, True ), \
"tempBlock2": colormap.alloc_color( "#837399", True, True ), \
@@ -28,6 +33,30 @@ class Desktop( gtk.EventBox ):
"tempBlock4": colormap.alloc_color( "#99AA22", True, True ), \
"tempBlock5": colormap.alloc_color( "#449977", True, True ) }
+ if True: # load clipmask
+ pix = gtk.gdk.pixbuf_new_from_file(Config.IMAGE_ROOT+'jam-blockMask.png')
+ pixels = pix.get_pixels()
+ stride = pix.get_rowstride()
+ channels = pix.get_n_channels()
+ bitmap = ""
+ byte = 0
+ shift = 0
+ for j in range(pix.get_height()):
+ offset = stride*j
+ for i in range(pix.get_width()):
+ r = pixels[i*channels+offset]
+ if r != "\0": byte += 1 << shift
+ shift += 1
+ if shift > 7:
+ bitmap += "%c" % byte
+ byte = 0
+ shift = 0
+ if shift > 0:
+ bitmap += "%c" % byte
+ byte = 0
+ shift = 0
+ self.clipMask = gtk.gdk.bitmap_create_from_data( None, bitmap, pix.get_width(), pix.get_height() )
+
self.dirtyRectToAdd = gtk.gdk.Rectangle() # used by the invalidate_rect function
self.screenBuf = None
self.screenBufDirty = False
@@ -71,24 +100,24 @@ class Desktop( gtk.EventBox ):
def addBlock( self, blockClass, blockData, loc = (-1,-1), drag = False ):
- block = blockClass( self, self.gc )
+ block = blockClass( self, self.gc, blockData )
if loc[0] != -1: x = loc[0]
- else: x = self.alloc.width//2 - blockClass.WIDTH_DIV2
+ else: x = self.alloc.width//2
if loc[1] != -1: y = loc[1]
- elif drag: y = self.alloc.height - blockClass.HEIGHT
- else: y = self.alloc.height//2 - blockClass.HEIGHT_DIV2
+ elif drag: y = self.alloc.height - block.height//2
+ else: y = self.alloc.height//2
if drag:
win = gtk.gdk.get_default_root_window()
display = win.get_display()
screen = display.get_default_screen()
- display.warp_pointer( screen, self.absoluteLoc[0] + x + blockClass.WIDTH_DIV2, self.absoluteLoc[1] + y + blockClass.HEIGHT_DIV2 )
+ display.warp_pointer( screen, self.absoluteLoc[0] + x, self.absoluteLoc[1] + y )
self._beginDrag( block )
- block.setLoc( x, y )
+ block.setLoc( x - block.width//2, y - block.height//2 )
else:
self.blocks.append( block )
- block.setLoc( x, y )
+ block.setLoc( x - block.width//2, y - block.height//2 )
@@ -155,7 +184,7 @@ class Desktop( gtk.EventBox ):
if self.clickedBlock.canChild and len(self.blocks):
for i in range(len(self.blocks)-1, -1, -1):
- handled = self.blocks[i].testChild( self.clickedBlock.getLoc() )
+ handled = self.blocks[i].testChild( self.clickedBlock.getAttachLoc() )
if handled:
if self.possibleParent != handled:
if self.possibleParent:
@@ -189,6 +218,7 @@ class Desktop( gtk.EventBox ):
self.screenBuf.draw_rectangle( self.gc, True, startX, startY, self.screenBufDirtyRect.width, self.screenBufDirtyRect.height )
# draw blocks
+ self.gc.set_clip_mask( self.clipMask )
for block in self.blocks:
block.draw( startX, startY, stopX, stopY, self.screenBuf )
@@ -214,6 +244,8 @@ class Desktop( gtk.EventBox ):
if self.possibleDelete:
return
+ self.gc.set_clip_mask( self.clipMask )
+
# draw possible parent
if self.possibleParent:
self.possibleParent.drawHighlight( startX, startY, stopX, stopY, DA.window )
diff --git a/Jam/JamMain.py b/Jam/JamMain.py
index 8c203a1..ac1fb12 100644
--- a/Jam/JamMain.py
+++ b/Jam/JamMain.py
@@ -6,7 +6,7 @@ import gtk
from SubActivity import SubActivity
from Jam.Desktop import Desktop
-from Jam.Picker import Picker
+import Jam.Picker as Picker
class JamMain(SubActivity):
@@ -37,10 +37,13 @@ class JamMain(SubActivity):
self.GUI["bankVBox"].pack_start( self.GUI["bankTabs"], False, False )
self.GUI["bankInstrumentsTab"] = gtk.RadioButton( None, "Instruments" )
+ self.GUI["bankInstrumentsTab"].connect( "clicked", lambda w: self.setPicker( Picker.Instrument, None ) )
self.GUI["bankTabs"].pack_start( self.GUI["bankInstrumentsTab"] )
self.GUI["bankDrumsTab"] = gtk.RadioButton( self.GUI["bankInstrumentsTab"], "Drums" )
+ self.GUI["bankDrumsTab"].connect( "clicked", lambda w: self.setPicker( Picker.Drum ) )
self.GUI["bankTabs"].pack_start( self.GUI["bankDrumsTab"] )
self.GUI["bankLoopsTab"] = gtk.RadioButton( self.GUI["bankInstrumentsTab"], "Loops" )
+ self.GUI["bankLoopsTab"].connect( "clicked", lambda w: self.setPicker( Picker.Loop ) )
self.GUI["bankTabs"].pack_start( self.GUI["bankLoopsTab"] )
if True: # Picker
@@ -48,23 +51,16 @@ class JamMain(SubActivity):
self.GUI["bankPicker"].set_size_request( -1, 149 )
self.GUI["bankVBox"].pack_start( self.GUI["bankPicker"], False, False )
- self.GUI["bankScrollLeft"] = gtk.Button( "<" )
- self.GUI["bankPicker"].pack_start( self.GUI["bankScrollLeft"], False, False )
-
- self.GUI["bankScrolledWindow"] = gtk.ScrolledWindow()
- self.GUI["bankScrolledWindow"].set_policy( gtk.POLICY_ALWAYS, gtk.POLICY_NEVER )
- self.GUI["bankPicker"].pack_start( self.GUI["bankScrolledWindow"] )
-
- self.GUI["bankScrollRight"] = gtk.Button( ">" )
- self.GUI["bankPicker"].pack_start( self.GUI["bankScrollRight"], False, False )
-
- self.GUI["pickerInstruments"] = Picker( self, Picker.INSTRUMENTS )
- self.GUI["pickerInstruments"].show_all()
-
- self.GUI["bankScrolledWindow"].add_with_viewport( self.GUI["pickerInstruments"] )
+ self.pickers = {}
+ self.pickerScroll = {}
+ for type in [ Picker.Instrument, Picker.Drum, Picker.Loop ]:
+ self.pickers[type] = type( self )
self.show_all()
+ self.curPicker = None
+ self.setPicker( Picker.Instrument )
+
def onActivate( self, arg ):
pass
@@ -76,3 +72,16 @@ class JamMain(SubActivity):
def getDesktop( self ):
return self.desktop
+
+ def setPicker( self, type, filter = None ):
+ if self.curPicker == type:
+ if self.pickers[self.curPicker].getFilter() == filter:
+ return
+ self.pickers[self.curPicker].setFilter( filter )
+ else:
+ if self.curPicker != None:
+ self.GUI["bankPicker"].remove( self.pickers[self.curPicker] )
+
+ self.GUI["bankPicker"].pack_start( self.pickers[type] )
+ self.curPicker = type
+
diff --git a/Jam/Picker.py b/Jam/Picker.py
index 5c1627b..6e436ef 100644
--- a/Jam/Picker.py
+++ b/Jam/Picker.py
@@ -3,44 +3,73 @@ import pygtk
pygtk.require( '2.0' )
import gtk
+import random #TEMP
+
import Jam.Block as Block
class Picker( gtk.HBox ):
- INSTRUMENTS = 0
- LOOPS = 1
- DRUMKITS = 2
-
- def __init__( self, owner, type, filter = None ):
+ def __init__( self, owner, filter = None ):
gtk.HBox.__init__( self )
self.owner = owner
- self.type = type
self.filter = filter
self.desktop = owner.getDesktop()
- # temp
- dummy = gtk.Button("dummy")
- dummy.add_events(gtk.gdk.BUTTON_MOTION_MASK)
- dummy.connect( "button-press-event", self.button_press )
- dummy.connect( "button-release-event", self.button_release )
- dummy.connect( "motion-notify-event", self.motion_notify )
+ self.scrollLeft = gtk.Button( "<" )
+ self.pack_start( self.scrollLeft, False, False )
+
+ self.scrolledWindow = gtk.ScrolledWindow()
+ self.scrolledWindow.set_policy( gtk.POLICY_ALWAYS, gtk.POLICY_NEVER )
+ self.pack_start( self.scrolledWindow )
+ self.hadjustment = self.scrolledWindow.get_hadjustment()
+
+ self.scrollRight = gtk.Button( ">" )
+ self.pack_start( self.scrollRight, False, False )
+
+ self.pickerBox = gtk.HBox()
+ self.scrolledWindow.add_with_viewport( self.pickerBox )
+
+ self.show_all()
+
+ self.scroll = {}
+ self.scroll[filter] = 0
+
+ self.blocks = []
- self.pack_start( dummy, False, False )
+ def addBlock( self, name ):
+ block = gtk.Button(name)
+ block.add_events(gtk.gdk.BUTTON_MOTION_MASK)
+ block.connect( "button-press-event", self.button_press )
+ block.connect( "button-release-event", self.button_release )
+ block.connect( "motion-notify-event", self.motion_notify )
+
+ self.blocks.append( block )
+
+ # TODO test against filter
+ self.pickerBox.pack_start( block, False, False )
+ block.show()
+
+ def getFilter( self ):
+ return filter
+
+ def setFilter( self, filter ):
+ # TODO apply filter
+
+ self.scroll[self.filter] = self.hadjustment.get_value()
+
+ if self.scroll.has_key( filter ):
+ self.hadjustment.set_value( self.scroll[filter] )
+ else:
+ self.hadjustment.set_value( 0 )
+ self.scroll[filter] = 0
+
+ self.filter = filter
def button_press( self, widget, event ):
- alloc = widget.get_allocation()
- if self.type == Picker.INSTRUMENTS:
- blockClass = Block.Instrument
- blockData = []
- loc = ( alloc.x + event.x - blockClass.WIDTH_DIV2, -1 )
- elif self.type == Picker.LOOPS:
- pass
- elif self.type == Picker.DRUMKITS:
- pass
- self.desktop.addBlock( blockClass, blockData, loc, True )
+ pass
def button_release( self, widget, event ):
self.desktop.button_release( widget, event )
@@ -49,3 +78,51 @@ class Picker( gtk.HBox ):
self.desktop.motion_notify( widget, event )
+class Instrument( Picker ):
+
+ def __init__( self, owner, filter = None ):
+ Picker.__init__( self, owner, filter )
+
+ self.type = Instrument
+
+ self.addBlock( "Instrument" )
+
+ def button_press( self, widget, event ):
+ 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.Instrument, [], loc, True )
+
+
+class Drum( Picker ):
+
+ def __init__( self, owner, filter = None ):
+ Picker.__init__( self, owner, filter )
+
+ self.type = Drum
+
+ self.addBlock( "Drum" )
+
+ def button_press( self, widget, event ):
+ 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.Drum, [], loc, True )
+
+
+class Loop( Picker ):
+
+ def __init__( self, owner, filter = None ):
+ Picker.__init__( self, owner, filter )
+
+ self.type = Loop
+
+ self.addBlock( "Loop" )
+
+ def button_press( self, widget, event ):
+ 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, { "beats": random.randint(1,8) }, loc, True )
+
+