def draw(self, ctx, startX, stopX): # we don't need to draw and no one after us will draw if stopX < self.x: return False # we don't need to draw, but maybe a later note does if startX > self.x + self.width: return True # draw fill ctx.save() ctx.set_source_rgb(CairoUtil.gdk_color_to_cairo( self.colors["Preview_Note_Fill"])) ctx.rectangle(self.x + 1, self.y + 1, self.width - 2, self.owner.sampleNoteHeight - 2) ctx.fill() # draw border if self.selected: ctx.set_source_rgb(CairoUtil.gdk_color_to_cairo( self.colors["Preview_Note_Selected"])) else: ctx.set_source_rgb(CairoUtil.gdk_color_to_cairo( self.colors["Preview_Note_Border"])) #self.gc.set_clip_origin( self.x, self.y ) endX = self.x + self.width - 3 ctx.rectangle(self.x, self.y, self.width - 3, self.owner.sampleNoteHeight) ctx.fill() #self.gc.set_clip_origin( endX-self.owner.sampleNoteMask.endOffset, self.y ) ctx.rectangle(endX, self.y, 3, self.owner.sampleNoteHeight) ctx.fill() ctx.restore() return True # we drew something
def draw(self, ctx, startX, stopX): # we don't need to draw and no one after us will draw if stopX < self.x: return False # we don't need to draw, but maybe a later note does if startX > self.x + self.width: return True # draw fill ctx.save() ctx.set_source_rgb( CairoUtil.gdk_color_to_cairo(self.colors["Preview_Note_Fill"])) ctx.rectangle(self.x + 1, self.y + 1, self.width - 2, self.owner.sampleNoteHeight - 2) ctx.fill() # draw border if self.selected: ctx.set_source_rgb( CairoUtil.gdk_color_to_cairo( self.colors["Preview_Note_Selected"])) else: ctx.set_source_rgb( CairoUtil.gdk_color_to_cairo( self.colors["Preview_Note_Border"])) #self.gc.set_clip_origin( self.x, self.y ) endX = self.x + self.width - 3 ctx.rectangle(self.x, self.y, self.width - 3, self.owner.sampleNoteHeight) ctx.fill() #self.gc.set_clip_origin( endX-self.owner.sampleNoteMask.endOffset, self.y ) ctx.rectangle(endX, self.y, 3, self.owner.sampleNoteHeight) ctx.fill() ctx.restore() return True # we drew something
def prepareInstrumentImage(self, id, img_path): try: pix = cairo.ImageSurface.create_from_png(img_path) except: logging.error("JamMain:: file does not exist: %s", img_path) pix = cairo.ImageSurface.create_from_png(imagefile('generic.png')) x = (Block.Block.WIDTH - pix.get_width()) // 2 y = (Block.Block.HEIGHT - pix.get_height()) // 2 img = cairo.ImageSurface(cairo.FORMAT_ARGB32, Block.Block.WIDTH, Block.Block.HEIGHT) # TODO: two images? may be we can draw the rectangle with cairo later ctx = cairo.Context(img) ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.colors["Bg_Inactive"])) ctx.rectangle(0, 0, Block.Block.WIDTH, Block.Block.HEIGHT) ctx.translate(x, y) ctx.set_source_surface(pix, 0, 0) ctx.paint() self.instrumentImage[id] = img img2 = cairo.ImageSurface(cairo.FORMAT_ARGB32, Block.Block.WIDTH, Block.Block.HEIGHT) ctx2 = cairo.Context(img2) ctx2.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.colors["Bg_Active"])) ctx2.rectangle(0, 0, Block.Block.WIDTH, Block.Block.HEIGHT) ctx2.translate(x, y) ctx2.set_source_surface(pix, 0, 0) ctx2.paint() self.instrumentImageActive[id] = img2
def prepareInstrumentImage(self, id, img_path): try: pix = cairo.ImageSurface.create_from_png(img_path) except: logging.error("JamMain:: file does not exist: %s", img_path) pix = cairo.ImageSurface.create_from_png(imagefile('generic.png')) x = (Block.Block.WIDTH - pix.get_width()) // 2 y = (Block.Block.HEIGHT - pix.get_height()) // 2 img = cairo.ImageSurface(cairo.FORMAT_ARGB32, Block.Block.WIDTH, Block.Block.HEIGHT) # TODO: two images? may be we can draw the rectangle with cairo later ctx = cairo.Context(img) ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Bg_Inactive"])) ctx.rectangle(0, 0, Block.Block.WIDTH, Block.Block.HEIGHT) ctx.translate(x, y) ctx.set_source_surface(pix, 0, 0) ctx.paint() self.instrumentImage[id] = img img2 = cairo.ImageSurface(cairo.FORMAT_ARGB32, Block.Block.WIDTH, Block.Block.HEIGHT) ctx2 = cairo.Context(img2) ctx2.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Bg_Active"])) ctx2.rectangle(0, 0, Block.Block.WIDTH, Block.Block.HEIGHT) ctx2.translate(x, y) ctx2.set_source_surface(pix, 0, 0) ctx2.paint() self.instrumentImageActive[id] = img2
def _doDraw(self, startX, startY, stopX, stopY, ctx, highlight=False, key_highlight=False): x = max(startX, self.x) y = max(startY, self.y) loop = self.img[self.active] width = loop.get_width() height = loop.get_height() ctx.save() CairoUtil.draw_loop_mask(ctx, x, y, width, height) ctx.set_line_width(3) if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Inactive"])) ctx.fill_preserve() if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Inactive"])) if highlight: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.stroke() ctx.save() # draw block ctx.translate(x, y) ctx.set_source_surface(loop) ctx.paint() ctx.restore() #draw key if self.keyActive: ctx.save() ctx.translate(x + Loop.KEYRECT[0], y + Loop.KEYRECT[1]) ctx.set_source_surface(self.keyImage[self.active]) ctx.paint() ctx.restore() if key_highlight: ctx.save() ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.translate(x + Loop.KEYRECT[0] - 1, y + Loop.KEYRECT[1] - 1) CairoUtil.draw_round_rect(ctx, 0, 0, Block.KEYSIZE + 2, Block.KEYSIZE + 2, radio=5) ctx.stroke() ctx.restore() ctx.restore()
def _doDraw(self, startX, startY, stopX, stopY, ctx, highlight=False, key_highlight=False): 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 ctx.save() # draw border CairoUtil.draw_drum_mask(ctx, x, y, width) ctx.set_line_width(3) if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Inactive"])) ctx.fill_preserve() if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Inactive"])) if highlight: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.stroke() # draw block ctx.save() ctx.translate(x, y) ctx.set_source_surface(self.img[self.active]) ctx.paint() ctx.restore() # draw key ctx.save() ctx.translate(self.x + Drum.KEYRECT[0], self.y + Drum.KEYRECT[1]) ctx.set_source_surface(self.keyImage[self.active]) ctx.paint() ctx.restore() ctx.restore() if key_highlight: ctx.save() ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.translate(x + Drum.KEYRECT[0] - 1, y + Drum.KEYRECT[1] - 1) CairoUtil.draw_round_rect(ctx, 0, 0, Block.KEYSIZE + 2, Block.KEYSIZE + 2, radio=5) ctx.stroke() ctx.restore()
def draw(self): self.cr = self.window.cairo_create() self.cr.set_source_rgb(self.fillcolor[0], self.fillcolor[1], self.fillcolor[2]) CairoUtil.draw_round_rect(self.cr, self.drawX - self.width // 2, self.drawY - self.height // 2, self.width, self.height, 10) self.cr.fill() self.cr.set_line_width(3) self.cr.set_source_rgb(self.strokecolor[0], self.strokecolor[1], self.strokecolor[2]) CairoUtil.draw_round_rect(self.cr, self.drawX - self.width // 2, self.drawY - self.height // 2, self.width, self.height, 10) self.cr.stroke()
def updateLoopImage(self, id): page = self.noteDB.getPage(id) width = Block.Loop.WIDTH[page.beats] height = Block.Loop.HEIGHT surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) """ ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Bg_Inactive"])) ctx.rectangle(0, 0, width, height) ctx.fill() """ self._drawNotes(ctx, page.beats, self.noteDB.getNotesByTrack(id, 0), False) self.loopImage[id] = surface #self.gc.set_clip_rectangle((0, 0, width, height)) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Bg_Active"])) ctx.rectangle(0, 0, width, height) ctx.fill() self._drawNotes(ctx, page.beats, self.noteDB.getNotesByTrack(id, 0), True) self.loopImageActive[id] = surface
def updateLoopImage(self, id): page = self.noteDB.getPage(id) width = Block.Loop.WIDTH[page.beats] height = Block.Loop.HEIGHT surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) """ ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Bg_Inactive"])) ctx.rectangle(0, 0, width, height) ctx.fill() """ self._drawNotes(ctx, page.beats, self.noteDB.getNotesByTrack(id, 0), False) self.loopImage[id] = surface #self.gc.set_clip_rectangle((0, 0, width, height)) surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.colors["Bg_Active"])) ctx.rectangle(0, 0, width, height) ctx.fill() self._drawNotes(ctx, page.beats, self.noteDB.getNotesByTrack(id, 0), True) self.loopImageActive[id] = surface
def addBlock(self, id, name): # match data structure of Block.Loop data = {"name": _('Loop'), "id": id} self.owner.updateLoopImage(data["id"]) loop = self.owner.getLoopImage(data["id"]) page = self.owner.noteDB.getPage(id) width = Block.Loop.WIDTH[page.beats] height = Block.Loop.HEIGHT surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) # draw bg ctx.save() ctx.set_line_width(3) ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.colors["Bg_Inactive"])) CairoUtil.draw_loop_mask(ctx, 0, 0, width, height) ctx.fill_preserve() ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.colors["Border_Inactive"])) ctx.stroke() ctx.restore() # draw block ctx.set_source_surface(loop) ctx.paint() # may be there are a better way to put the content of the surface in # a GtkImage pixbuf_data = StringIO.StringIO() surface.write_to_png(pixbuf_data) pxb_loader = GdkPixbuf.PixbufLoader.new_with_type('png') pxb_loader.write(pixbuf_data.getvalue()) pxb_loader.close() image = Gtk.Image.new_from_pixbuf(pxb_loader.get_pixbuf()) block = Gtk.EventBox() block.modify_bg(Gtk.StateType.NORMAL, self.colors["Picker_Bg"]) block.add(image) Picker.addBlock(self, data, data["name"], block)
def addBlock(self, id, name): # match data structure of Block.Loop data = {"name": _("Loop"), "id": id} self.owner.updateLoopImage(data["id"]) loop = self.owner.getLoopImage(data["id"]) page = self.owner.noteDB.getPage(id) width = Block.Loop.WIDTH[page.beats] height = Block.Loop.HEIGHT surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) # draw bg ctx.save() ctx.set_line_width(3) ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(self.colors["Bg_Inactive"])) CairoUtil.draw_loop_mask(ctx, 0, 0, width, height) ctx.fill_preserve() ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(self.colors["Border_Inactive"])) ctx.stroke() ctx.restore() # draw block ctx.set_source_surface(loop) ctx.paint() # may be there are a better way to put the content of the surface in # a GtkImage pixbuf_data = StringIO.StringIO() surface.write_to_png(pixbuf_data) pxb_loader = GdkPixbuf.PixbufLoader.new_with_type("png") pxb_loader.write(pixbuf_data.getvalue()) pxb_loader.close() image = Gtk.Image.new_from_pixbuf(pxb_loader.get_pixbuf()) block = Gtk.EventBox() block.modify_bg(Gtk.StateType.NORMAL, self.colors["Picker_Bg"]) block.add(image) Picker.addBlock(self, data, data["name"], block)
def _doDraw(self, startX, startY, stopX, stopY, ctx, highlight=False): 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 ctx.save() # draw border CairoUtil.draw_round_rect(ctx, x, y, width, height) ctx.set_line_width(3) if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Inactive"])) ctx.fill_preserve() if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Inactive"])) if highlight: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.stroke() ctx.translate(x, y) ctx.set_source_surface(self.img[self.active]) ctx.paint() ctx.restore()
def _doDraw(self, startX, startY, stopX, stopY, ctx, highlight=False): 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 ctx.save() # draw border CairoUtil.draw_round_rect(ctx, x, y, width, height) ctx.set_line_width(3) if self.active: ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.owner.colors["Bg_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Inactive"])) ctx.fill_preserve() if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Inactive"])) if highlight: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.stroke() ctx.translate(x, y) ctx.set_source_surface(self.img[self.active]) ctx.paint() ctx.restore()
def _prepare_key_image(self, text, bg_color, border_color): img = cairo.ImageSurface(cairo.FORMAT_ARGB32, Block.Block.KEYSIZE, Block.Block.KEYSIZE) ctx = cairo.Context(img) pango_layout = PangoCairo.create_layout(ctx) fontDesc = Pango.FontDescription("bold") pango_layout.set_font_description(fontDesc) pango_layout.set_text(unicode(text), len(unicode(text))) extents = pango_layout.get_pixel_extents() x = (Block.Block.KEYSIZE - extents[1].width) // 2 y = (Block.Block.KEYSIZE - extents[1].height) // 2 ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(border_color)) CairoUtil.draw_round_rect(ctx, 0, 0, Block.Block.KEYSIZE, Block.Block.KEYSIZE, radio=5) ctx.fill() ctx.translate(x, y) ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(bg_color)) PangoCairo.show_layout(ctx, pango_layout) ctx.stroke() return img
def addBlock(self, id): # match data structure of Block.Drum data = {"name": self.instrumentDB.instId[id].nameTooltip, "id": id} width = Block.Drum.WIDTH height = Block.Drum.HEIGHT surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) ctx.save() ctx.set_line_width(3) ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.colors["Bg_Inactive"])) CairoUtil.draw_drum_mask(ctx, 0, 0, width) ctx.fill_preserve() ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.colors["Border_Inactive"])) ctx.stroke() ctx.restore() # draw block ctx.set_source_surface(self.owner.getInstrumentImage(data["id"]), 0, 0) ctx.paint() # may be there are a better way to put the content of the surface in # a GtkImage pixbuf_data = StringIO.StringIO() surface.write_to_png(pixbuf_data) pxb_loader = GdkPixbuf.PixbufLoader.new_with_type('png') pxb_loader.write(pixbuf_data.getvalue()) pxb_loader.close() image = Gtk.Image.new_from_pixbuf(pxb_loader.get_pixbuf()) block = Gtk.EventBox() block.modify_bg(Gtk.StateType.NORMAL, self.colors["Picker_Bg"]) block.add(image) Picker.addBlock(self, data, data["name"], block)
def addBlock(self, id): # match data structure of Block.Drum data = {"name": self.instrumentDB.instId[id].nameTooltip, "id": id} width = Block.Drum.WIDTH height = Block.Drum.HEIGHT surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) ctx = cairo.Context(surface) ctx.save() ctx.set_line_width(3) ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(self.colors["Bg_Inactive"])) CairoUtil.draw_drum_mask(ctx, 0, 0, width) ctx.fill_preserve() ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(self.colors["Border_Inactive"])) ctx.stroke() ctx.restore() # draw block ctx.set_source_surface(self.owner.getInstrumentImage(data["id"]), 0, 0) ctx.paint() # may be there are a better way to put the content of the surface in # a GtkImage pixbuf_data = StringIO.StringIO() surface.write_to_png(pixbuf_data) pxb_loader = GdkPixbuf.PixbufLoader.new_with_type("png") pxb_loader.write(pixbuf_data.getvalue()) pxb_loader.close() image = Gtk.Image.new_from_pixbuf(pxb_loader.get_pixbuf()) block = Gtk.EventBox() block.modify_bg(Gtk.StateType.NORMAL, self.colors["Picker_Bg"]) block.add(image) Picker.addBlock(self, data, data["name"], block)
def _drawNotes(self, ctx, beats, notes, active): #self.gc.set_clip_mask(self.sampleNoteMask) ctx.save() if active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Note_Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Note_Border_Inactive"])) line_width = self.sampleNoteHeight - 2 ctx.set_line_width(line_width) ctx.set_line_cap(cairo.LINE_CAP_ROUND) for note in notes: # draw N notes x = self.ticksToPixels(note.cs.onset) # include end cap offset endX = self.ticksToPixels(note.cs.onset + note.cs.duration) - 3 width = endX - x if width < 5: width = 5 y = self.pitchToPixels(note.cs.pitch) ctx.move_to(x + 1, y + (line_width / 2)) ctx.line_to(x + width - 1, y + (line_width / 2)) ctx.stroke() ctx.restore()
def _drawNotes(self, ctx, beats, notes, active): #self.gc.set_clip_mask(self.sampleNoteMask) ctx.save() if active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Note_Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.colors["Note_Border_Inactive"])) line_width = self.sampleNoteHeight - 2 ctx.set_line_width(line_width) ctx.set_line_cap(cairo.LINE_CAP_ROUND) for note in notes: # draw N notes x = self.ticksToPixels(note.cs.onset) # include end cap offset endX = self.ticksToPixels(note.cs.onset + note.cs.duration) - 3 width = endX - x if width < 5: width = 5 y = self.pitchToPixels(note.cs.pitch) ctx.move_to(x + 1, y + (line_width / 2)) ctx.line_to(x + width - 1, y + (line_width / 2)) ctx.stroke() ctx.restore()
def _prepare_key_image(self, text, bg_color, border_color): img = cairo.ImageSurface(cairo.FORMAT_ARGB32, Block.Block.KEYSIZE, Block.Block.KEYSIZE) ctx = cairo.Context(img) pango_layout = PangoCairo.create_layout(ctx) fontDesc = Pango.FontDescription("bold") pango_layout.set_font_description(fontDesc) pango_layout.set_text(unicode(text), len(unicode(text))) extents = pango_layout.get_pixel_extents() x = (Block.Block.KEYSIZE - extents[1].width) // 2 y = (Block.Block.KEYSIZE - extents[1].height) // 2 ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(border_color)) CairoUtil.draw_round_rect(ctx, 0, 0, Block.Block.KEYSIZE, Block.Block.KEYSIZE, radio=5) ctx.fill() ctx.translate(x, y) ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(bg_color)) PangoCairo.show_layout(ctx, pango_layout) ctx.stroke() return img
def draw(self, ctx): startX = self.screenBufDirtyRect.x startY = self.screenBufDirtyRect.y stopX = startX + self.screenBufDirtyRect.width stopY = startY + self.screenBufDirtyRect.height #self.gc.set_clip_rectangle( self.screenBufDirtyRect ) # draw background ctx.save() ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo(self.colors["bg"])) ctx.rectangle(startX, startY, self.screenBufDirtyRect.width, self.screenBufDirtyRect.height ) ctx.fill() ctx.restore() # draw blocks #self.gc.set_clip_mask( self.blockMask ) for block in self.blocks: block.draw(startX, startY, stopX, stopY, ctx) self.screenBufDirty = False
def __init__(self, activity): GObject.GObject.__init__(self) self.activity = activity self.instrumentDB = InstrumentDB.getRef() self.noteDB = NoteDB.NoteDB() #-- initial settings ---------------------------------- self.tempo = Config.PLAYER_TEMPO self.beatDuration = 60.0 / self.tempo self.ticksPerSecond = Config.TICKS_PER_BEAT * self.tempo / 60.0 self.volume = 0.5 self.csnd = new_csound_client() for i in range(0, 9): self.csnd.setTrackVolume(100, i) # csnd expects a range 0-100 for now self.csnd.setMasterVolume(self.volume * 100) self.csnd.setTempo(self.tempo) self.muted = False #-- Drawing ------------------------------------------- def darken(hex): hexToDec = { "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15 } r = int(0.7 * (16 * hexToDec[hex[1]] + hexToDec[hex[2]])) g = int(0.7 * (16 * hexToDec[hex[3]] + hexToDec[hex[4]])) b = int(0.7 * (16 * hexToDec[hex[5]] + hexToDec[hex[6]])) return r * 256, g * 256, b * 256 def lighten(hex): hexToDec = { "0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15 } r = 255 - int(0.7 * (255 - (16 * hexToDec[hex[1]] + hexToDec[hex[2]]))) g = 255 - int(0.7 * (255 - (16 * hexToDec[hex[3]] + hexToDec[hex[4]]))) b = 255 - int(0.7 * (255 - (16 * hexToDec[hex[5]] + hexToDec[hex[6]]))) return r * 256, g * 256, b * 256 xoColor = profile.get_color() if not xoColor: xoColorKey = ("#8D8D8D,#FFDDEA") xoColor = XoColor(xoColorKey) # colors in Config and in XoColor are strings, # the colors in style are style.Color, transform all to Gdk.Color self.colors = {"bg": CairoUtil.get_gdk_color(Config.PANEL_BCK_COLOR), "black": style.COLOR_BLACK.get_gdk_color(), #"Picker_Bg": colormap.alloc_color("#404040"), #"Picker_Bg_Inactive": colormap.alloc_color("#808080"), "Picker_Bg": style.COLOR_TOOLBAR_GREY.get_gdk_color(), "Picker_Bg_Inactive": style.COLOR_BUTTON_GREY.get_gdk_color(), "Picker_Fg": style.COLOR_WHITE.get_gdk_color(), "Border_Active": \ CairoUtil.get_gdk_color(xoColor.get_stroke_color()), "Border_Inactive": CairoUtil.get_gdk_color("#8D8D8D"), "Border_Highlight": CairoUtil.get_gdk_color("#FFFFFF"), "Bg_Active": CairoUtil.get_gdk_color(xoColor.get_fill_color()), "Bg_Inactive": CairoUtil.get_gdk_color("#DBDBDB"), "Preview_Note_Fill": CairoUtil.get_gdk_color(Config.BG_COLOR), "Preview_Note_Border": CairoUtil.get_gdk_color(Config.FG_COLOR), "Preview_Note_Selected": style.COLOR_WHITE.get_gdk_color(), # TODO: lighten here can be removed, check if is used in other # places "Note_Fill_Active": Gdk.Color(*lighten("#590000")), # base "Border_Active" "Note_Fill_Inactive": Gdk.Color(*lighten("#8D8D8D")), # base "Border_Inactive" "Beat_Line": CairoUtil.get_gdk_color("#959595")} self.colors["Note_Border_Active"] = self.colors["Border_Active"] self.colors["Note_Border_Inactive"] = self.colors["Border_Inactive"] self.sampleNoteHeight = 7 self.sampleBg = cairo.ImageSurface.create_from_png( imagefile('sampleBG.png')) self.loopPitchOffset = 4 self.loopTickOffset = 13 self.pitchPerPixel = float(Config.NUMBER_OF_POSSIBLE_PITCHES - 1) / \ (Block.Loop.HEIGHT - 2 * self.loopPitchOffset - \ self.sampleNoteHeight) self.pixelsPerPitch = float(Block.Loop.HEIGHT - \ 2 * self.loopPitchOffset - self.sampleNoteHeight) / \ (Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH) self.pixelsPerTick = Block.Loop.BEAT / float(Config.TICKS_PER_BEAT) self.ticksPerPixel = 1.0 / self.pixelsPerTick #-- Instruments --------------------------------------- self.instrumentImage = {} self.instrumentImageActive = {} for inst in self.instrumentDB.getSet("All"): if not inst.kitStage: self.prepareInstrumentImage(inst.instrumentId, inst.img) self.csnd.load_instrument(inst.name) #-- Loop Images --------------------------------------- self.loopImage = {} # get filled in through updateLoopImage self.loopImageActive = {} #-- Key Images ---------------------------------------- self.keyImage = {} self.keyImageActive = {} # use hardware key codes to work on any keyboard layout (hopefully) self.valid_shortcuts = { 18: "9", 19: "0", 20: "-", 21: "=", 32: "O", 33: "P", 34: "[", 35: "]", 47: ";", 48: "'", 51: "\\", 60: ".", 61: "/", None: " " } for key in self.valid_shortcuts.keys(): self.prepareKeyImage(key) #-- Toolbars ------------------------------------------ self.jamToolbar = JamToolbar(self) jam_toolbar_button = ToolbarButton(label=_('Jam'), page=self.jamToolbar, icon_name='voltemp') self.jamToolbar.show() jam_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(jam_toolbar_button, -1) self.beatToolbar = BeatToolbar(self) beat_toolbar_button = ToolbarButton(label=_('Beat'), page=self.beatToolbar, icon_name='heart') self.beatToolbar.show() beat_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(beat_toolbar_button, -1) self.desktopToolbar = DesktopToolbar(self) desktop_toolbar_button = ToolbarButton(label=_('Desktop'), page=self.desktopToolbar, icon_name='jam-presets-list') self.desktopToolbar.show() desktop_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(desktop_toolbar_button, -1) if Config.FEATURES_MIC or Config.FEATURES_NEWSOUNDS: self.recordToolbar = RecordToolbar(self) record_toolbar_button = ToolbarButton(label=_('Record'), page=self.recordToolbar, icon_name='microphone') self.recordToolbar.show() record_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(record_toolbar_button, -1) separator = Gtk.SeparatorToolItem() separator.props.draw = True separator.set_expand(False) self.activity.toolbar_box.toolbar.insert(separator, -1) separator.show() common_playback_buttons(self.activity.toolbar_box.toolbar, self) #-- GUI ----------------------------------------------- if True: # GUI self.modify_bg(Gtk.StateType.NORMAL, self.colors["bg"]) self.GUI = {} self.GUI["mainVBox"] = Gtk.VBox() self.add(self.GUI["mainVBox"]) #-- Desktop ------------------------------------------- self.desktop = self.GUI["desktop"] = Desktop(self) self.GUI["mainVBox"].pack_start(self.GUI["desktop"], True, True, 0) #-- Bank ---------------------------------------------- separator = Gtk.Label(label=" ") separator.set_size_request(-1, style.TOOLBOX_SEPARATOR_HEIGHT) self.GUI["mainVBox"].pack_start(separator, False, True, 0) self.GUI["notebook"] = Gtk.Notebook() self.GUI["notebook"].set_scrollable(True) self.GUI["notebook"].modify_bg(Gtk.StateType.NORMAL, self.colors["Picker_Bg"]) self.GUI["notebook"].modify_bg(Gtk.StateType.ACTIVE, self.colors["Picker_Bg_Inactive"]) # TODO gtk3 no available anymore? #self.GUI["notebook"].props.tab_vborder = style.TOOLBOX_TAB_VBORDER #self.GUI["notebook"].props.tab_hborder = style.TOOLBOX_TAB_HBORDER self.GUI["notebook"].set_size_request(-1, scale(160)) self.GUI["notebook"].connect("switch-page", self.setPicker) self.GUI["mainVBox"].pack_start(self.GUI["notebook"], False, False, 0) self.pickers = {} self.pickerScroll = {} for type in [Picker.Instrument, Picker.Drum, Picker.Loop]: self.pickers[type] = type(self) def prepareLabel(name): label = Gtk.Label(label=Tooltips.categories.get(name) or name) label.set_alignment(0.0, 0.5) label.modify_fg(Gtk.StateType.NORMAL, self.colors["Picker_Fg"]) label.modify_fg(Gtk.StateType.ACTIVE, self.colors["Picker_Fg"]) return label self.GUI["notebook"].append_page(self.pickers[Picker.Drum], prepareLabel(_("Drum Kits"))) self.GUI["notebook"].append_page(self.pickers[Picker.Loop], prepareLabel(_("Loops"))) sets = self.instrumentDB.getLabels()[:] sets.sort() for set in sets: page = Gtk.HBox() page.set = set self.GUI["notebook"].append_page(page, prepareLabel(set)) self.show_all() self.GUI["notebook"].set_current_page(0) #-- Keyboard ------------------------------------------ self.key_dict = {} self.nextTrack = 2 self.keyboardListener = None self.recordingNote = None self.keyMap = {} # default instrument self._updateInstrument( self.instrumentDB.instNamed["kalimba"].instrumentId, 0.5) self.instrumentStack = [] # metronome page = NoteDB.Page(1, local=False) self.metronomePage = self.noteDB.addPage(-1, page) self.metronome = False #-- Drums --------------------------------------------- self.drumLoopId = None # use dummy values for now self.drumFillin = Fillin( 2, 100, self.instrumentDB.instNamed["drum1kit"].instrumentId, 0, 1) #-- Desktops ------------------------------------------ self.curDesktop = None # copy preset desktops path = Config.FILES_DIR + "/Desktops/" filelist = os.listdir(path) for file in filelist: shutil.copyfile(path + file, Config.TMP_DIR + '/' + file) #-- Network ------------------------------------------- self.network = Net.Network() self.network.addWatcher(self.networkStatusWatcher) self.network.connectMessage(Net.HT_SYNC_REPLY, self.processHT_SYNC_REPLY) self.network.connectMessage(Net.HT_TEMPO_UPDATE, self.processHT_TEMPO_UPDATE) self.network.connectMessage(Net.PR_SYNC_QUERY, self.processPR_SYNC_QUERY) self.network.connectMessage(Net.PR_TEMPO_QUERY, self.processPR_TEMPO_QUERY) self.network.connectMessage(Net.PR_REQUEST_TEMPO_CHANGE, self.processPR_REQUEST_TEMPO_CHANGE) # sync self.syncQueryStart = {} self.syncTimeout = None self.heartbeatLoop = self.csnd.loopCreate() self.syncBeats = 4 self.syncTicks = self.syncBeats * Config.TICKS_PER_BEAT self.offsetTicks = 0 # offset from the true heartbeat self.csnd.loopSetNumTicks(self.syncTicks * HEARTBEAT_BUFFER, self.heartbeatLoop) self.heartbeatStart = time.time() self.csnd.loopStart(self.heartbeatLoop) self.curBeat = 0 self.beatWheelTimeout = GObject.timeout_add(100, self.updateBeatWheel) # data packing classes self.packer = xdrlib.Packer() self.unpacker = xdrlib.Unpacker("") # handle forced networking if self.network.isHost(): self.updateSync() self.syncTimeout = GObject.timeout_add(1000, self.updateSync) elif self.network.isPeer(): self.sendTempoQuery() self.syncTimeout = GObject.timeout_add(1000, self.updateSync) self.activity.connect("shared", self.shared) if self.activity.shared_activity: # PEER self.activity.shared_activity.connect("buddy-joined", self.buddy_joined) self.activity.shared_activity.connect("buddy-left", self.buddy_left) self.activity.connect("joined", self.joined) self.network.setMode(Net.MD_WAIT) #-- Final Set Up -------------------------------------- self.setVolume(self.volume) self.setTempo(self.tempo) #self.activity.toolbar_box.set_current_toolbar(1) # JamToolbar self.setDesktop(0, True)
def draw(self, widget, cr): if self.alloc == None: return area = widget.get_allocation() startX = area.x - self.alloc.x startY = area.y - self.alloc.y stopX = startX + area.width stopY = startY + area.height #saveForeground = gc.foreground # Note: could maybe do some optimization to fill only areas that are # within the dirty rect, but drawing seems to be quite fast compared # to python code, so just leave it at clipping by each geometry feature cr.set_source_rgb(*CairoUtil.gdk_color_to_cairo(self.bordercolor)) if self.borderW: if stopY > self.corner and startY < self.heightMINcorner: if startX < self.borderW: # draw left border cr.rectangle(self.alloc.x, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2) cr.fill() if stopX > self.widthMINborderW: # draw right border cr.rectangle(self.xPLUwidthMINborderW, self.yPLUcorner, self.borderW, self.heightMINcornerMUL2) cr.fill() if stopX > self.corner and startX < self.widthMINcorner: if startY < self.borderW: # draw top border cr.rectangle(self.xPLUcorner, self.alloc.y, self.widthMINcornerMUL2, self.borderW) cr.fill() if stopY > self.heightMINborderW: # draw bottom border cr.rectangle(self.xPLUcorner, self.yPLUheightMINborderW, self.widthMINcornerMUL2, self.borderW) cr.fill() if startX < self.corner: if startY < self.corner: # draw top left corner cr.rectangle(self.alloc.x, self.alloc.y, self.corner, self.corner) gc.foreground = self.fillcolor self.window.draw_arc(gc, True, self.roundX1, self.roundY1, self.roundD, self.roundD, self.rightAngle, self.rightAngle) gc.foreground = self.bordercolor if stopY > self.heightMINcorner: # draw bottom left corner self.window.draw_rectangle(gc, True, self.alloc.x, self.yPLUheightMINcorner, self.corner, self.corner) gc.foreground = self.fillcolor self.window.draw_arc(gc, True, self.roundX1, self.roundY2, self.roundD, self.roundD, -self.rightAngle, -self.rightAngle) gc.foreground = self.bordercolor if stopX > self.widthMINcorner: if startY < self.corner: # draw top right corner self.window.draw_rectangle(gc, True, self.xPLUwidthMINcorner, self.alloc.y, self.corner, self.corner) gc.foreground = self.fillcolor self.window.draw_arc(gc, True, self.roundX2, self.roundY1, self.roundD, self.roundD, 0, self.rightAngle) gc.foreground = self.bordercolor if stopY > self.heightMINcorner: # draw bottom right corner self.window.draw_rectangle(gc, True, self.xPLUwidthMINcorner, self.yPLUheightMINcorner, self.corner, self.corner) gc.foreground = self.fillcolor self.window.draw_arc(gc, True, self.roundX2, self.roundY2, self.roundD, self.roundD, 0, -self.rightAngle) gc.foreground = self.bordercolor gc.foreground = self.fillcolor if startX < self.widthMINcorner and stopX > self.corner: # draw centre fill if startY < self.heightMINborderW and stopY > self.borderW: self.window.draw_rectangle(gc, True, self.xPLUcorner, self.yPLUborderW, self.widthMINcornerMUL2, self.heightMINborderWMUL2) if startX < self.corner and stopX > self.borderW: # draw left fill if startY < self.heightMINcorner and stopY > self.corner: self.window.draw_rectangle(gc, True, self.xPLUborderW, self.yPLUcorner, self.cornerMINborderW, self.heightMINcornerMUL2) if startX < self.widthMINborderW and stopX > self.widthMINcorner: # draw right fill if startY < self.heightMINcorner and stopY > self.corner: self.window.draw_rectangle(gc, True, self.xPLUwidthMINcorner, self.yPLUcorner, self.cornerMINborderW, self.heightMINcornerMUL2) gc.foreground = saveForeground return False
def __init__(self, activity): GObject.GObject.__init__(self) self.activity = activity self.instrumentDB = InstrumentDB.getRef() self.noteDB = NoteDB.NoteDB() #-- initial settings ---------------------------------- self.tempo = Config.PLAYER_TEMPO self.beatDuration = 60.0 / self.tempo self.ticksPerSecond = Config.TICKS_PER_BEAT * self.tempo / 60.0 self.volume = 0.5 self.csnd = new_csound_client() for i in range(0, 9): self.csnd.setTrackVolume(100, i) # csnd expects a range 0-100 for now self.csnd.setMasterVolume(self.volume * 100) self.csnd.setTempo(self.tempo) self.muted = False #-- Drawing ------------------------------------------- def darken(hex): hexToDec = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15} r = int(0.7 * (16 * hexToDec[hex[1]] + hexToDec[hex[2]])) g = int(0.7 * (16 * hexToDec[hex[3]] + hexToDec[hex[4]])) b = int(0.7 * (16 * hexToDec[hex[5]] + hexToDec[hex[6]])) return r * 256, g * 256, b * 256 def lighten(hex): hexToDec = {"0": 0, "1": 1, "2": 2, "3": 3, "4": 4, "5": 5, "6": 6, "7": 7, "8": 8, "9": 9, "A": 10, "B": 11, "C": 12, "D": 13, "E": 14, "F": 15, "a": 10, "b": 11, "c": 12, "d": 13, "e": 14, "f": 15} r = 255 - int(0.7 * (255 - ( 16 * hexToDec[hex[1]] + hexToDec[hex[2]]))) g = 255 - int(0.7 * (255 - ( 16 * hexToDec[hex[3]] + hexToDec[hex[4]]))) b = 255 - int(0.7 * (255 - ( 16 * hexToDec[hex[5]] + hexToDec[hex[6]]))) return r * 256, g * 256, b * 256 xoColor = profile.get_color() if not xoColor: xoColorKey = ("#8D8D8D,#FFDDEA") xoColor = XoColor(xoColorKey) # colors in Config and in XoColor are strings, # the colors in style are style.Color, transform all to Gdk.Color self.colors = {"bg": CairoUtil.get_gdk_color(Config.PANEL_BCK_COLOR), "black": style.COLOR_BLACK.get_gdk_color(), #"Picker_Bg": colormap.alloc_color("#404040"), #"Picker_Bg_Inactive": colormap.alloc_color("#808080"), "Picker_Bg": style.COLOR_TOOLBAR_GREY.get_gdk_color(), "Picker_Bg_Inactive": style.COLOR_BUTTON_GREY.get_gdk_color(), "Picker_Fg": style.COLOR_WHITE.get_gdk_color(), "Border_Active": \ CairoUtil.get_gdk_color(xoColor.get_stroke_color()), "Border_Inactive": CairoUtil.get_gdk_color("#8D8D8D"), "Border_Highlight": CairoUtil.get_gdk_color("#FFFFFF"), "Bg_Active": CairoUtil.get_gdk_color(xoColor.get_fill_color()), "Bg_Inactive": CairoUtil.get_gdk_color("#DBDBDB"), "Preview_Note_Fill": CairoUtil.get_gdk_color(Config.BG_COLOR), "Preview_Note_Border": CairoUtil.get_gdk_color(Config.FG_COLOR), "Preview_Note_Selected": style.COLOR_WHITE.get_gdk_color(), # TODO: lighten here can be removed, check if is used in other # places "Note_Fill_Active": Gdk.Color(*lighten("#590000")), # base "Border_Active" "Note_Fill_Inactive": Gdk.Color(*lighten("#8D8D8D")), # base "Border_Inactive" "Beat_Line": CairoUtil.get_gdk_color("#959595")} self.colors["Note_Border_Active"] = self.colors["Border_Active"] self.colors["Note_Border_Inactive"] = self.colors["Border_Inactive"] self.sampleNoteHeight = 7 self.sampleBg = cairo.ImageSurface.create_from_png( imagefile('sampleBG.png')) self.loopPitchOffset = 4 self.loopTickOffset = 13 self.pitchPerPixel = float(Config.NUMBER_OF_POSSIBLE_PITCHES - 1) / \ (Block.Loop.HEIGHT - 2 * self.loopPitchOffset - \ self.sampleNoteHeight) self.pixelsPerPitch = float(Block.Loop.HEIGHT - \ 2 * self.loopPitchOffset - self.sampleNoteHeight) / \ (Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH) self.pixelsPerTick = Block.Loop.BEAT / float(Config.TICKS_PER_BEAT) self.ticksPerPixel = 1.0 / self.pixelsPerTick #-- Instruments --------------------------------------- self.instrumentImage = {} self.instrumentImageActive = {} for inst in self.instrumentDB.getSet("All"): if not inst.kitStage: self.prepareInstrumentImage(inst.instrumentId, inst.img) self.csnd.load_instrument(inst.name) #-- Loop Images --------------------------------------- self.loopImage = {} # get filled in through updateLoopImage self.loopImageActive = {} #-- Key Images ---------------------------------------- self.keyImage = {} self.keyImageActive = {} # use hardware key codes to work on any keyboard layout (hopefully) self.valid_shortcuts = {18: "9", 19: "0", 20: "-", 21: "=", 32: "O", 33: "P", 34: "[", 35: "]", 47: ";", 48: "'", 51: "\\", 60: ".", 61: "/", None: " "} for key in self.valid_shortcuts.keys(): self.prepareKeyImage(key) #-- Toolbars ------------------------------------------ self.jamToolbar = JamToolbar(self) jam_toolbar_button = ToolbarButton(label=_('Jam'), page=self.jamToolbar, icon_name='voltemp') self.jamToolbar.show() jam_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(jam_toolbar_button, -1) self.beatToolbar = BeatToolbar(self) beat_toolbar_button = ToolbarButton(label=_('Beat'), page=self.beatToolbar, icon_name='heart') self.beatToolbar.show() beat_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(beat_toolbar_button, -1) self.desktopToolbar = DesktopToolbar(self) desktop_toolbar_button = ToolbarButton(label=_('Desktop'), page=self.desktopToolbar, icon_name='jam-presets-list') self.desktopToolbar.show() desktop_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(desktop_toolbar_button, -1) if Config.FEATURES_MIC or Config.FEATURES_NEWSOUNDS: self.recordToolbar = RecordToolbar(self) record_toolbar_button = ToolbarButton(label=_('Record'), page=self.recordToolbar, icon_name='microphone') self.recordToolbar.show() record_toolbar_button.show() self.activity.toolbar_box.toolbar.insert(record_toolbar_button, -1) separator = Gtk.SeparatorToolItem() separator.props.draw = True separator.set_expand(False) self.activity.toolbar_box.toolbar.insert(separator, -1) separator.show() common_playback_buttons(self.activity.toolbar_box.toolbar, self) #-- GUI ----------------------------------------------- if True: # GUI self.modify_bg(Gtk.StateType.NORMAL, self.colors["bg"]) self.GUI = {} self.GUI["mainVBox"] = Gtk.VBox() self.add(self.GUI["mainVBox"]) #-- Desktop ------------------------------------------- self.desktop = self.GUI["desktop"] = Desktop(self) self.GUI["mainVBox"].pack_start(self.GUI["desktop"], True, True, 0) #-- Bank ---------------------------------------------- separator = Gtk.Label(label=" ") separator.set_size_request(-1, style.TOOLBOX_SEPARATOR_HEIGHT) self.GUI["mainVBox"].pack_start(separator, False, True, 0) self.GUI["notebook"] = Gtk.Notebook() self.GUI["notebook"].set_scrollable(True) self.GUI["notebook"].modify_bg(Gtk.StateType.NORMAL, self.colors["Picker_Bg"]) self.GUI["notebook"].modify_bg(Gtk.StateType.ACTIVE, self.colors["Picker_Bg_Inactive"]) # TODO gtk3 no available anymore? #self.GUI["notebook"].props.tab_vborder = style.TOOLBOX_TAB_VBORDER #self.GUI["notebook"].props.tab_hborder = style.TOOLBOX_TAB_HBORDER self.GUI["notebook"].set_size_request(-1, scale(160)) self.GUI["notebook"].connect("switch-page", self.setPicker) self.GUI["mainVBox"].pack_start(self.GUI["notebook"], False, False, 0) self.pickers = {} self.pickerScroll = {} for type in [Picker.Instrument, Picker.Drum, Picker.Loop]: self.pickers[type] = type(self) def prepareLabel(name): label = Gtk.Label(label=Tooltips.categories.get(name) or name) label.set_alignment(0.0, 0.5) label.modify_fg(Gtk.StateType.NORMAL, self.colors["Picker_Fg"]) label.modify_fg(Gtk.StateType.ACTIVE, self.colors["Picker_Fg"]) return label self.GUI["notebook"].append_page(self.pickers[Picker.Drum], prepareLabel(_("Drum Kits"))) self.GUI["notebook"].append_page(self.pickers[Picker.Loop], prepareLabel(_("Loops"))) sets = self.instrumentDB.getLabels()[:] sets.sort() for set in sets: page = Gtk.HBox() page.set = set self.GUI["notebook"].append_page(page, prepareLabel(set)) self.show_all() self.GUI["notebook"].set_current_page(0) #-- Keyboard ------------------------------------------ self.key_dict = {} self.nextTrack = 2 self.keyboardListener = None self.recordingNote = None self.keyMap = {} # default instrument self._updateInstrument( self.instrumentDB.instNamed["kalimba"].instrumentId, 0.5) self.instrumentStack = [] # metronome page = NoteDB.Page(1, local=False) self.metronomePage = self.noteDB.addPage(-1, page) self.metronome = False #-- Drums --------------------------------------------- self.drumLoopId = None # use dummy values for now self.drumFillin = Fillin( 2, 100, self.instrumentDB.instNamed["drum1kit"].instrumentId, 0, 1) #-- Desktops ------------------------------------------ self.curDesktop = None # copy preset desktops path = Config.FILES_DIR + "/Desktops/" filelist = os.listdir(path) for file in filelist: shutil.copyfile(path + file, Config.TMP_DIR + '/' + file) #-- Network ------------------------------------------- self.network = Net.Network() self.network.addWatcher(self.networkStatusWatcher) self.network.connectMessage(Net.HT_SYNC_REPLY, self.processHT_SYNC_REPLY) self.network.connectMessage(Net.HT_TEMPO_UPDATE, self.processHT_TEMPO_UPDATE) self.network.connectMessage(Net.PR_SYNC_QUERY, self.processPR_SYNC_QUERY) self.network.connectMessage(Net.PR_TEMPO_QUERY, self.processPR_TEMPO_QUERY) self.network.connectMessage(Net.PR_REQUEST_TEMPO_CHANGE, self.processPR_REQUEST_TEMPO_CHANGE) # sync self.syncQueryStart = {} self.syncTimeout = None self.heartbeatLoop = self.csnd.loopCreate() self.syncBeats = 4 self.syncTicks = self.syncBeats * Config.TICKS_PER_BEAT self.offsetTicks = 0 # offset from the true heartbeat self.csnd.loopSetNumTicks(self.syncTicks * HEARTBEAT_BUFFER, self.heartbeatLoop) self.heartbeatStart = time.time() self.csnd.loopStart(self.heartbeatLoop) self.curBeat = 0 self.beatWheelTimeout = GObject.timeout_add(100, self.updateBeatWheel) # data packing classes self.packer = xdrlib.Packer() self.unpacker = xdrlib.Unpacker("") # handle forced networking if self.network.isHost(): self.updateSync() self.syncTimeout = GObject.timeout_add(1000, self.updateSync) elif self.network.isPeer(): self.sendTempoQuery() self.syncTimeout = GObject.timeout_add(1000, self.updateSync) self.activity.connect("shared", self.shared) if self.activity.shared_activity: # PEER self.activity.shared_activity.connect("buddy-joined", self.buddy_joined) self.activity.shared_activity.connect("buddy-left", self.buddy_left) self.activity.connect("joined", self.joined) self.network.setMode(Net.MD_WAIT) #-- Final Set Up -------------------------------------- self.setVolume(self.volume) self.setTempo(self.tempo) #self.activity.toolbar_box.set_current_toolbar(1) # JamToolbar self.setDesktop(0, True)
def _doDraw(self, startX, startY, stopX, stopY, ctx, highlight=False, key_highlight=False): x = max(startX, self.x) y = max(startY, self.y) loop = self.img[self.active] width = loop.get_width() height = loop.get_height() ctx.save() CairoUtil.draw_loop_mask(ctx, x, y, width, height) ctx.set_line_width(3) if self.active: ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.owner.colors["Bg_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Inactive"])) ctx.fill_preserve() if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Inactive"])) if highlight: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.stroke() ctx.save() # draw block ctx.translate(x, y) ctx.set_source_surface(loop) ctx.paint() ctx.restore() #draw key if self.keyActive: ctx.save() ctx.translate(x + Loop.KEYRECT[0], y + Loop.KEYRECT[1]) ctx.set_source_surface(self.keyImage[self.active]) ctx.paint() ctx.restore() if key_highlight: ctx.save() ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.translate(x + Loop.KEYRECT[0] - 1, y + Loop.KEYRECT[1] - 1) CairoUtil.draw_round_rect(ctx, 0, 0, Block.KEYSIZE + 2, Block.KEYSIZE + 2, radio=5) ctx.stroke() ctx.restore() ctx.restore()
def _doDraw(self, startX, startY, stopX, stopY, ctx, highlight=False, key_highlight=False): 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 ctx.save() # draw border CairoUtil.draw_drum_mask(ctx, x, y, width) ctx.set_line_width(3) if self.active: ctx.set_source_rgb( *CairoUtil.gdk_color_to_cairo(self.owner.colors["Bg_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Bg_Inactive"])) ctx.fill_preserve() if self.active: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Active"])) else: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Inactive"])) if highlight: ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.stroke() # draw block ctx.save() ctx.translate(x, y) ctx.set_source_surface(self.img[self.active]) ctx.paint() ctx.restore() # draw key ctx.save() ctx.translate(self.x + Drum.KEYRECT[0], self.y + Drum.KEYRECT[1]) ctx.set_source_surface(self.keyImage[self.active]) ctx.paint() ctx.restore() ctx.restore() if key_highlight: ctx.save() ctx.set_source_rgb(*CairoUtil.gdk_color_to_cairo( self.owner.colors["Border_Highlight"])) ctx.translate(x + Drum.KEYRECT[0] - 1, y + Drum.KEYRECT[1] - 1) CairoUtil.draw_round_rect(ctx, 0, 0, Block.KEYSIZE + 2, Block.KEYSIZE + 2, radio=5) ctx.stroke() ctx.restore()