diff options
-rw-r--r-- | Jam/Block.py | 302 | ||||
-rw-r--r-- | Jam/Desktop.py | 52 | ||||
-rw-r--r-- | Jam/JamMain.py | 39 | ||||
-rw-r--r-- | Jam/Picker.py | 123 | ||||
-rw-r--r-- | Resources/Images/jam-blockMask.png | bin | 0 -> 4016 bytes | |||
-rw-r--r-- | SynthLab/SynthLabWindow.py | 38 |
6 files changed, 455 insertions, 99 deletions
diff --git a/Jam/Block.py b/Jam/Block.py index 907ed3d..dff54bf 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,23 +159,23 @@ 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: + if stopY <= self.y or startY >= self.endY: return False self._drawB( startX, startY, stopX, stopY, pixmap ) def _drawB( self, startX, startY, stopX, stopY, pixmap ): - if stopX < self.x: + if stopX <= self.x: return False if self.child: self.child._drawB( startX, startY, stopX, stopX, pixmap ) - if startX > self.endX: + if startX >= self.endX: return False self._doDraw( startX, startY, stopX, stopY, pixmap ) @@ -175,33 +183,249 @@ 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 ): + x = max( startX, self.x ) + y = max( startY, self.y ) + endX = min( stopX, self.endX ) + endY = min( stopY, self.endY ) + width = endX - x + height = endY - y + + # 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, x, y, width, 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, x, y, width, 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 ): + x = max( startX, self.x ) + y = max( startY, self.y ) + endX = min( stopX, self.endX ) + endY = min( stopY, self.endY ) + width = endX - x + height = endY - y + + # 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, x, y, width, 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, x, y, width, 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 ): + y = max( startY, self.y ) + endY = min( stopY, self.endY ) + height = endY - y + + #-- draw head ----------------------------------------- + + if self.x + Loop.HEAD > startX: + x = max( startX, self.x ) + endX = min( stopX, self.x + Loop.HEAD ) + width = endX - x + + # 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, x, y, width, 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, x, y, width, height ) + + #-- draw beats ---------------------------------------- + + beats = self.data["beats"] - 1 # last beat is drawn with the tail + curx = self.x + Loop.HEAD + while beats > 3: + if curx >= stopX: + return + elif curx + Loop.BEAT_MUL3 > startX: + x = max( startX, curx ) + endX = min( stopX, curx + Loop.BEAT_MUL3 ) + width = endX - x + + # 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( curx-Loop.MASK_BEAT, self.y ) + pixmap.draw_rectangle( self.gc, True, x, y, width, 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( curx-Loop.MASK_BEAT, self.y-self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) + + curx += Loop.BEAT_MUL3 + beats -= 3 + if beats: + if curx >= stopX: + return + endX = curx + Loop.BEAT*beats + if endX > startX: + x = max( startX, curx ) + endX = min( stopX, endX ) + width = endX - x + + # 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( curx-Loop.MASK_BEAT, self.y ) + pixmap.draw_rectangle( self.gc, True, x, y, width, 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( curx-Loop.MASK_BEAT, self.y-self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, height ) + + curx += Loop.BEAT*beats + + #-- draw tail ----------------------------------------- + + if curx >= stopX: + return + + x = max( startX, curx ) + endX = min( stopX, self.endX ) + width = endX - x + + # 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( curx-Loop.MASK_TAIL, self.y ) + pixmap.draw_rectangle( self.gc, True, x, y, width, 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( curx-Loop.MASK_TAIL, self.y-self.height ) + pixmap.draw_rectangle( self.gc, True, x, y, width, 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..0a71d6f 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 ) @@ -117,11 +146,11 @@ class Desktop( gtk.EventBox ): self.dragging = False if self.possibleParent: - self.possibleParent.invalidate_rect( False ) self.possibleParent.addChild( self.clickedBlock ) root = self.possibleParent.getRoot() self.blocks.remove(root) self.blocks.append(root) + root.invalidateBranch( True ) self.possibleParent = None else: self.blocks.append( self.clickedBlock ) @@ -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 ) + + diff --git a/Resources/Images/jam-blockMask.png b/Resources/Images/jam-blockMask.png Binary files differnew file mode 100644 index 0000000..05dd1ed --- /dev/null +++ b/Resources/Images/jam-blockMask.png diff --git a/SynthLab/SynthLabWindow.py b/SynthLab/SynthLabWindow.py index 66ba2a0..279d026 100644 --- a/SynthLab/SynthLabWindow.py +++ b/SynthLab/SynthLabWindow.py @@ -113,7 +113,7 @@ class SynthLabWindow(SubActivity): self.mainBox = gtk.HBox() self.subBox = gtk.HBox() self.drawingBox = RoundVBox( 10, Config.PANEL_COLOR, Config.PANEL_COLOR ) - self.drawingBox.set_border_width(Config.PANEL_SPACING) + self.drawingBox.set_border_width(0) self.infoBox = RoundVBox( 10, Config.TOOLBAR_BCK_COLOR, Config.TOOLBAR_BCK_COLOR ) self.infoBox.set_border_width(Config.PANEL_SPACING) self.infoBox.set_size_request(300, 750) @@ -161,7 +161,7 @@ class SynthLabWindow(SubActivity): slider4Init = parametersTable[tablePos+3] sliderTextColor = gtk.gdk.color_parse(Config.WHITE_COLOR) - sliderHeight = 268 + sliderHeight = 240 self.p1Adjust = gtk.Adjustment(slider1Init, slider1Min, slider1Max, slider1Step, slider1Step, 0) self.p1Adjust.connect("value-changed", self.sendTables, 1) @@ -215,7 +215,7 @@ class SynthLabWindow(SubActivity): text_bg_color = gtk.gdk.color_parse(Config.TOOLBAR_BCK_COLOR) textScroller = gtk.ScrolledWindow() textScroller.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - textScroller.set_size_request(270, 310) + textScroller.set_size_request(270, 302) self.textBuf = gtk.TextBuffer(None) self.textBuf.set_text(self.infoText) self.textViewer = gtk.TextView(self.textBuf) @@ -281,7 +281,7 @@ class SynthLabWindow(SubActivity): self.drawingArea.connect( "button-release-event", self.handleButtonRelease ) self.drawingArea.connect( "motion-notify-event", self.handleMotion ) self.drawingArea.connect("expose-event", self.draw) - self.drawingBox.pack_start(self.drawingArea, False, False, 5) + self.drawingBox.pack_start(self.drawingArea, False, False, 0) tempFile = 'synthTemp' if tempFile in os.listdir(Config.PREF_DIR): @@ -333,11 +333,11 @@ class SynthLabWindow(SubActivity): self.synthObjectsParameters.fxsParameters ) def updateViewer(self): - self.viewType = SynthLabConstants.SYNTHTYPES[self.objectType][self.choosenType] selectedType = SynthLabConstants.CHOOSE_TYPE[self.objectType][self.choosenType] - info = SynthLabConstants.SYNTHPARA[selectedType][4] - self.viewParam = SynthLabConstants.SYNTHPARA[selectedType][self.curSlider-1] + ': ' + self.recallSliderValue(self.curSlider) - self.infoText = self.viewType + ': ' + info + '\n\n' + self.viewParam + infoType = SynthLabConstants.SYNTHPARA[selectedType][4] + #infoPara = SynthLabConstants.SYNTHPARA[selectedType][4+self.curSlider] + infoPara = "Parameter's info not yet set" + self.infoText = infoType + '\n\n' + infoPara self.textBuf.set_text(self.infoText) def recallSliderValue( self, num ): @@ -434,6 +434,9 @@ class SynthLabWindow(SubActivity): for i in range(4): self.synthObjectsParameters.setOutputParameter(i, sliderListValue[i]) self.updateViewer() + selectedType = SynthLabConstants.CHOOSE_TYPE[self.objectType][self.choosenType] + _str = SynthLabConstants.SYNTHTYPES[self.objectType][self.choosenType] + '\n' + SynthLabConstants.SYNTHPARA[selectedType][self.curSlider-1] + ': ' + self.recallSliderValue(self.curSlider) + self.parameterUpdate(_str) def handleSliderRelease(self, widget, data=None): if self.instanceID != 12: @@ -444,6 +447,10 @@ class SynthLabWindow(SubActivity): widget.grab_focus() self.sendTables(widget, slider) + #selectedType = SynthLabConstants.CHOOSE_TYPE[self.objectType][self.choosenType] + #_str = SynthLabConstants.SYNTHTYPES[self.objectType][self.choosenType] + '\n' + SynthLabConstants.SYNTHPARA[selectedType][self.curSlider-1] + ': ' + self.recallSliderValue(self.curSlider) + #self.parameterUpdate(_str) + def onKeyPress(self,widget,event): key = event.hardware_keycode if key not in Config.KEY_MAP: @@ -729,7 +736,10 @@ class SynthLabWindow(SubActivity): _str = SynthLabConstants.SYNTHTYPES[obj/4][self.typesTable[obj]] + _(': controller output') elif gate[0] == 1: choosen = SynthLabConstants.CHOOSE_TYPE[obj/4][self.typesTable[obj]] - _str = SynthLabConstants.SYNTHTYPES[obj/4][self.typesTable[obj]] + ': ' + SynthLabConstants.SYNTHPARA[choosen][gate[1]] + parametersTable = self.synthObjectsParameters.choiceParamsSet[obj/4] + tablePos = (obj % 4)*4+gate[1] + paraVal = '%.2f' % parametersTable[tablePos] + _str = SynthLabConstants.SYNTHTYPES[obj/4][self.typesTable[obj]] + '\n' + SynthLabConstants.SYNTHPARA[choosen][gate[1]] + ': ' + paraVal if self.overGateObj == self.instanceID: gateNum = self.overGate[1]+1 exec 'self.slider%s.grab_focus()' % str(gateNum) @@ -931,6 +941,7 @@ class SynthLabWindow(SubActivity): # draw separator self.gc.foreground = self.lineColor + buf.draw_line( self.gc, startX, 1, stopX, 1 ) buf.draw_line( self.gc, startX, self.separatorY, stopX, self.separatorY ) # draw objects @@ -1191,7 +1202,7 @@ class SynthLabWindow(SubActivity): map.draw_rectangle( gc, True, 0, 0, pix.get_width(), pix.get_height() ) map.draw_pixbuf( gc, pix, 0, 0, 0, 0, pix.get_width(), pix.get_height(), gtk.gdk.RGB_DITHER_NONE ) self.pixmap[type].append(map) - + for i in range(len(SynthLabConstants.CONTROL_TYPES_PLUS)): loadImg( 0, SynthLabConstants.CONTROL_TYPES_PLUS[i] ) for i in range(len(SynthLabConstants.SOURCE_TYPES_PLUS)): @@ -1199,7 +1210,7 @@ class SynthLabWindow(SubActivity): for i in range(len(SynthLabConstants.FX_TYPES_PLUS)): loadImg( 2, SynthLabConstants.FX_TYPES_PLUS[i] ) loadImg( 3, "speaker" ) - + pix = gtk.gdk.pixbuf_new_from_file(Config.IMAGE_ROOT+'synthlabMask.png') pixels = pix.get_pixels() stride = pix.get_rowstride() @@ -1217,7 +1228,10 @@ class SynthLabWindow(SubActivity): bitmap += "%c" % byte byte = 0 shift = 0 - bitmap += "%c" % byte + 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() ) def handleSave(self, widget, data): |