def __init__(self, group, mainImg_path, altImg_path, enterImg_path=None, backgroundFill=None): mainImg_path = imagefile(mainImg_path) altImg_path = imagefile(altImg_path) enterImg_path = imagefile(enterImg_path) Gtk.RadioButton.__init__(self) if group is not None: self.join_group(group) self.within = False self.clicked = False self.set_label('') self.image = {} self.iwidth = {} self.iwidthDIV2 = {} self.iheight = {} self.iheightDIV2 = {} self.backgroundFill = backgroundFill def prepareImage(name, path): if path.endswith(".png"): pix = cairo.ImageSurface.create_from_png(path) self.is_png = True elif path.endswith(".svg"): pix = GdkPixbuf.Pixbuf.new_from_file(path) self.is_png = False self.image[name] = pix self.iwidth[name] = pix.get_width() self.iwidthDIV2[name] = self.iwidth[name] // 2 self.iheight[name] = pix.get_height() self.iheightDIV2[name] = self.iheight[name] // 2 prepareImage("main", mainImg_path) prepareImage("alt", altImg_path) if enterImg_path != None: prepareImage("enter", enterImg_path) else: self.image["enter"] = self.image["main"] self.iwidth["enter"] = self.iwidth["main"] self.iwidthDIV2["enter"] = self.iwidthDIV2["main"] self.iheight["enter"] = self.iheight["main"] self.iheightDIV2["enter"] = self.iheightDIV2["main"] self.connect('enter-notify-event', self.on_btn_enter) self.connect('leave-notify-event', self.on_btn_leave) self.connect("toggled", self.toggleImage) self.connect('pressed', self.pressed) self.connect('released', self.released) self.connect('draw', self.draw) self.set_size_request(self.iwidth["main"], self.iheight["main"]) self.curImage = "main" self.queue_draw()
def __make_tempoSlider(self): """ slider 3 """ self.delayedTempo = 0 # used to store tempo updates while the slider is active self.tempoSliderActive = False self.tempoSliderBoxImgTop = gtk.Image() self.tempoSliderBoxImgTop.set_from_file( imagefile('tempo5.png')) self.tempoAdjustment = gtk.Adjustment( value=self.tempo, lower=Config.PLAYER_TEMPO_LOWER, upper=Config.PLAYER_TEMPO_UPPER, step_incr=1, page_incr=1, page_size=1) self.tempoSlider = ImageVScale( 'sliderbutvert.png', self.tempoAdjustment, 5) self.tempoSlider.set_inverted(True) self.tempoAdjustmentHandler = self.tempoAdjustment.connect( "value_changed", self.handleTempoSliderChange) self.tempoSlider.connect("button-press-event", self.handleTempoSliderPress) self.tempoSlider.connect("button-release-event", self.handleTempoSliderRelease) self.tooltips.set_tip(self.tempoSlider, Tooltips.TEMPO)
def _addInstrument(name, csoundInstrumentId, instrumentRegister, category, loopStart, loopEnd, crossDur, ampScale=1, kit=None, kitStage=False, volatile=False, nameTooltip=""): instrumentDB.addInstrumentFromArgs(name, csoundInstrumentId, instrumentRegister, loopStart, loopEnd, crossDur, ampScale, kit, name, imagefile(name + '.png'), category, kitStage=kitStage, volatile=volatile, nameTooltip=nameTooltip)
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 __make_volumeSlider(self): """ slider 4 """ self.volumeSliderBoxImgTop = gtk.Image() self.volumeSliderBoxImgTop.set_from_file( imagefile('volume2.png')) self.volumeAdjustment = gtk.Adjustment( value=self.volume, lower=0, upper=200, step_incr=1, page_incr=1, page_size=1) self.volumeSlider = ImageVScale( 'sliderbutbleu.png', self.volumeAdjustment, 5) self.volumeSlider.set_inverted(True) self.volumeAdjustment.connect( "value_changed", self.handleVolumeSlider) #volumeSlider.connect("button-release-event", self.handleVolumeSliderRelease) self.tooltips.set_tip(self.volumeSlider, Tooltips.VOL)
def __make_beatSlider(self): """ slider 2 """ self.beatSliderBoxImgTop = gtk.Image() self.beatSliderBoxImgTop.set_from_file( imagefile('beat3.png')) self.beatAdjustment = gtk.Adjustment( value=self.beat, lower=2, upper=12, step_incr=1, page_incr=0, page_size=0) self.beatSlider = ImageVScale( 'sliderbutjaune.png', self.beatAdjustment, 5, snap=1) self.beatSlider.set_inverted(True) self.beatAdjustment.connect( "value_changed", self.handleBeatSlider) self.beatSlider.connect( "button-release-event", self.handleBeatSliderRelease) self.tooltips.set_tip(self.beatSlider, Tooltips.BEAT)
def __make_geneSlider(self): """ slider 1 """ self.geneSliderBoxImgTop = gtk.Image() self.geneSliderBoxImgTop.set_from_file( imagefile('complex6.png')) self.geneAdjustment = gtk.Adjustment( value=self.regularity, lower=0, upper=1, step_incr=0.01, page_incr=0, page_size=0) self.geneSlider = ImageVScale( 'sliderbutbleu.png', self.geneAdjustment, 5) self.geneSlider.set_inverted(False) self.geneAdjustment.connect( "value_changed", self.handleGenerationSlider) self.geneSlider.connect( "button-release-event", self.handleGenerationSliderRelease) self.tooltips.set_tip(self.geneSlider, Tooltips.COMPL)
def handleVolumeSlider(self, adj): self.volume = adj.value self.csnd.setMasterVolume(self.volume) img = int(self.scale(self.volume, 0, 200, 0, 3.9)) self.volumeSliderBoxImgTop.set_from_file( imagefile('volume' + str(img) + '.png'))
def _updateTempo(self, val): if self.network.isHost(): t = time.time() percent = self.heartbeatElapsed() / self.beatDuration self.tempo = val self.beatDuration = 60.0/self.tempo self.ticksPerSecond = Config.TICKS_PER_BEAT*self.tempo/60.0 self.csnd.setTempo(self.tempo) self.sequencer.tempo = self.tempo self.drumFillin.setTempo(self.tempo) if self.network.isHost(): self.heatbeatStart = t - percent*self.beatDuration self.updateSync() self.sendTempoUpdate() img = int(self.scale(self.tempo, Config.PLAYER_TEMPO_LOWER, Config.PLAYER_TEMPO_UPPER, 1, 9)) self.tempoSliderBoxImgTop.set_from_file( imagefile('tempo' + str(img) + '.png'))
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 handleBeatSlider(self, adj): img = self.scale(int(adj.value), 2, 12, 1, 11) self.beatSliderBoxImgTop.set_from_file( imagefile('beat' + str(img) + '.png')) self.sequencer.beat = self.beat self.loop.beat = self.beat self.drumFillin.setBeats(self.beat)
def pickupNewBeat(self): self.beat = random.randint(2, 12) img = self.scale(self.beat, 2, 12, 1, 11) self.beatSliderBoxImgTop.set_from_file( imagefile('beat' + str(img) + '.png')) self.beatAdjustment.set_value(self.beat) self.regularity = random.randint(50, 100) * 0.01 img = int(self.regularity * 7)+1 self.geneSliderBoxImgTop.set_from_file( imagefile('complex' + str(img) + '.png')) self.geneAdjustment.set_value(self.regularity) self.sequencer.beat = self.beat self.loop.beat = self.beat self.drumFillin.setBeats(self.beat)
def handleBalanceSlider(self, adj): self.instVolume = int(adj.value) self.drumVolume = sqrt((100-self.instVolume) * 0.01) self.adjustDrumVolume() self.drumFillin.setVolume(self.drumVolume) instrumentVolume = sqrt(self.instVolume * 0.01) self.loop.adjustLoopVolume(instrumentVolume) self.sequencer.adjustSequencerVolume(instrumentVolume) img = int(self.scale(self.instVolume, 100, 0, 0, 4.9)) self._playToolbar.balanceSliderImgLeft.set_from_file( imagefile('dru' + str(img) + '.png')) img2 = int(self.scale(self.instVolume, 0, 100, 0, 4.9)) self._playToolbar.balanceSliderImgRight.set_from_file( imagefile('instr' + str(img2) + '.png'))
def __init__(self, image_name, adjustment=None, slider_border=0, insensitive_name=None, trough_color="#3D403A", snap=False): image_name = imagefile(image_name) Gtk.VScale.__init__(self) self.set_adjustment(adjustment) if snap: self.snap = 1 / snap else: self.snap = False #colormap = self.get_colormap() #self.troughcolor = colormap.alloc_color( # trough_color, True, True) img = Gtk.Image() img.set_from_file(image_name) self.sliderPixbuf = img.get_pixbuf() if insensitive_name == None: self.insensitivePixbuf = None else: img = Gtk.Image() img.set_from_file(insensitive_name) self.insensitivePixbuf = img.get_pixbuf() name = image_name + "ImageVScale" self.set_name(name) rc_str = """ style "scale_style" { GtkRange::slider_width = %d GtkScale::slider_length = %d } widget "*%s*" style "scale_style" """ % (self.sliderPixbuf.get_width(), self.sliderPixbuf.get_height(), name) Gtk.rc_parse_string(rc_str) self.pixbufWidth = self.sliderPixbuf.get_width() self.pixbufHeight = self.sliderPixbuf.get_height() self.sliderBorder = slider_border self.sliderBorderMUL2 = self.sliderBorder * 2 self.set_draw_value(False) #self.connect("expose-event", self.expose) self.connect("size-allocate", self.size_allocate) self.connect("button-release-event", self.button_release) adjustment.connect("value-changed", self.value_changed)
def handleReverbSlider(self, adj): self.reverb = adj.value self.drumFillin.setReverb(self.reverb) img = int(self.scale(self.reverb, 0, 1, 0, 4)) self._playToolbar.reverbSliderImgRight.set_from_file( imagefile('reverb' + str(img) + '.png')) self.keyboardStandAlone.setReverb(self.reverb)
def __init__(self, mainImg_path, clickImg_path=None): Gtk.ToggleButton.__init__(self) mainImg_path = imagefile(mainImg_path) clickImg_path = imagefile(clickImg_path) self.image = Gtk.Image() hbox = Gtk.HBox() hbox.pack_start(self.image, True, True, 0) self.mainImg = GdkPixbuf.Pixbuf.new_from_file(mainImg_path) self.clickImg_path = GdkPixbuf.Pixbuf.new_from_file(clickImg_path) self.image.set_from_pixbuf(self.mainImg) self.add(hbox) self.show_all() self.connect('toggled', self.toggleImage)
def __init__(self, mainImg_path, clickImg_path=None): gtk.Button.__init__(self) mainImg_path = imagefile(mainImg_path) clickImg_path = imagefile(clickImg_path) self.image = gtk.Image() hbox = gtk.HBox() hbox.pack_start(self.image, True, True, 0) self.mainImg = gtk.gdk.pixbuf_new_from_file(mainImg_path) self.clickImg_path = gtk.gdk.pixbuf_new_from_file(clickImg_path) self.image.set_from_pixbuf(self.mainImg) self.add(hbox) self.show_all() self.connect('pressed', self.on_btn_press) self.connect('released', self.on_btn_release)
def __init__(self, group, mainImg_path=None, width=100): gtk.RadioButton.__init__(self, group) mainImg_path = imagefile(mainImg_path) self.image = gtk.Image() mainImg = gtk.gdk.pixbuf_new_from_file_at_size( mainImg_path, width, width) self.image.set_from_pixbuf(mainImg) self.set_image(self.image) self.set_property('draw-indicator', False) self.show_all()
def __init__(self, image_name, adjustment=None, slider_border=0, insensitive_name=None, trough_color="#3D403A", snap=False): image_name = imagefile(image_name) Gtk.VScale.__init__(self) self.set_adjustment(adjustment) if snap: self.snap = 1 / snap else: self.snap = False img = Gtk.Image() img.set_from_file(image_name) self.sliderPixbuf = img.get_pixbuf() if insensitive_name == None: self.insensitivePixbuf = None else: img = Gtk.Image() img.set_from_file(insensitive_name) self.insensitivePixbuf = img.get_pixbuf() name = image_name + "ImageVScale" self.set_name(name) self.pixbufWidth = self.sliderPixbuf.get_width() self.pixbufHeight = self.sliderPixbuf.get_height() self.sliderBorder = slider_border self.set_draw_value(False) self.connect("draw", self.__draw_cb) self.connect("button-release-event", self.button_release) adjustment.connect("value-changed", self.value_changed)
def __init__(self, noteDB, owner, adjustment): Gtk.EventBox.__init__(self) self.num = 0 self.noteDB = noteDB self.owner = owner self.adjustment = adjustment #adjustment.connect( "changed", self.adjustmentChanged ) adjustment.connect("value-changed", self.adjustmentValue) self.drawingArea = Gtk.DrawingArea() self.drawingAreaDirty = False # is the drawingArea waiting to draw? self.add(self.drawingArea) self.dirtyRectToAdd = Gdk.Rectangle( ) # used by the invalidate_rect function self.selectedIds = [] self.displayedPage = -1 self.drumIndex = Config.NUMBER_OF_TRACKS - 1 self.trackRect = Config.THUMBNAIL_TRACK_RECT self.thumbnail = {} self.thumbnailDirty = {} self.thumbnailDirtyRect = {} self.bgColor = Gdk.Color.parse(Config.TOOLBAR_BCK_COLOR)[1] self.lineColor = Gdk.Color.parse(Config.THUMBNAIL_DRAG_COLOR)[1] self.displayedColor = Gdk.Color.parse( Config.THUMBNAIL_DISPLAYED_COLOR)[1] self.selectedColor = Gdk.Color.parse( Config.THUMBNAIL_SELECTED_COLOR)[1] # prepare thumbnail self.thumbnailBG = [] #self.gc.foreground = self.bgColor for i in range(4): pix = cairo.ImageSurface.create_from_png( imagefile('pageThumbnailBG%d.png' % i)) #pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailBG%d.png' % i)) self.thumbnailBG.append( cairo.ImageSurface(cairo.FORMAT_RGB24, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT)) cxt = cairo.Context(self.thumbnailBG[i]) cxt.set_source_rgb(*gdk_color_to_cairo(self.bgColor)) cxt.rectangle(0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT) cxt.fill() cxt.set_source_surface(pix, 0, 0) cxt.paint() # load clipmask #pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailMask.png')) pix = cairo.ImageSurface.create_from_png( imagefile("pageThumbnailMask.png")) pixels = pix.get_data() stride = pix.get_stride() #channels = pix.get_n_channels() channels = 4 bitmap = "" byte = 0 shift = 0 for j in range(pix.get_height()): offset = stride * j for i in range(pix.get_width()): if pixels[i * channels + offset] != "\0": byte += 1 << shift shift += 1 if shift > 7: bitmap += "%c" % byte byte = 0 shift = 0 if shift: bitmap += "%c" % byte byte = 0 shift = 0 #self.clipMask = cairo.ImageSurface.create_for_data(bytearray(bitmap), cairo.FORMAT_ARGB32, pix.get_width(), pix.get_height()) self.clearMask = Gdk.Rectangle() self.clearMask.x = 0 self.clearMask.y = 0 self.clearMask.width = 1200 self.clearMask.height = 800 self.pageOffset = 5 # offset the first page by this self.dropWidth = 5 # line thickness of the drop head self.dropWidthDIV2 = self.dropWidth // 2 self.pixelsPerPitch = float(self.trackRect[0][3] - 1) / ( Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH) self.pixelsPerPitchDrum = float(self.trackRect[self.drumIndex][3] - 1) / (Config.MAXIMUM_PITCH_DRUM - Config.MINIMUM_PITCH_DRUM) self.pixelsPerTick = [0] + [ float(self.trackRect[0][2] - 4) / (i * Config.TICKS_PER_BEAT) for i in range(1, Config.MAXIMUM_BEATS + 1) ] import logging logging.error('> %r %r %r', self.pixelsPerPitch, self.pixelsPerPitchDrum, self.pixelsPerTick) self.alloced = False self.width = self.baseWidth = self.height = -1 self.waitingForAlloc = True self.scrollTo = None self.clickX = -1 self.set_size_request(self.width, self.height) self.button1Down = False self.dragMode = None self.dropAt = -1 self.dropAtX = 0 self.visibleX = 0 self.visibleEndX = 0 self.add_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK) self.connect("size-allocate", self.size_allocated) self.drawingArea.connect("draw", self.draw) self.connect("button-press-event", self.handleButtonPress) self.connect("button-release-event", self.handleButtonRelease) self.connect("motion-notify-event", self.handleMotion)
def __init__( self, noteDB, owner, adjustment ): Gtk.EventBox.__init__( self ) self.num = 0 self.noteDB = noteDB self.owner = owner self.adjustment = adjustment #adjustment.connect( "changed", self.adjustmentChanged ) adjustment.connect( "value-changed", self.adjustmentValue ) self.drawingArea = Gtk.DrawingArea() self.drawingAreaDirty = False # is the drawingArea waiting to draw? self.add( self.drawingArea ) self.dirtyRectToAdd = Gdk.Rectangle() # used by the invalidate_rect function self.selectedIds = [] self.displayedPage = -1 self.drumIndex = Config.NUMBER_OF_TRACKS-1 self.trackRect = Config.THUMBNAIL_TRACK_RECT self.thumbnail = {} self.thumbnailDirty = {} self.thumbnailDirtyRect = {} self.bgColor = Gdk.Color.parse(Config.TOOLBAR_BCK_COLOR) [1] self.lineColor = Gdk.Color.parse(Config.THUMBNAIL_DRAG_COLOR) [1] self.displayedColor = Gdk.Color.parse(Config.THUMBNAIL_DISPLAYED_COLOR) [1] self.selectedColor = Gdk.Color.parse(Config.THUMBNAIL_SELECTED_COLOR) [1] # prepare thumbnail self.thumbnailBG = [] #self.gc.foreground = self.bgColor for i in range(4): pix = cairo.ImageSurface.create_from_png(imagefile('pageThumbnailBG%d.png' % i)) #pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailBG%d.png' % i)) self.thumbnailBG.append(cairo.ImageSurface(cairo.FORMAT_RGB24, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT)) cxt = cairo.Context(self.thumbnailBG[i]) cxt.set_source_rgb(*gdk_color_to_cairo(self.bgColor)) cxt.rectangle(0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT) cxt.fill() cxt.set_source_surface(pix, 0, 0) cxt.paint() # load clipmask #pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailMask.png')) pix = cairo.ImageSurface.create_from_png(imagefile("pageThumbnailMask.png")) pixels = pix.get_data() stride = pix.get_stride() #channels = pix.get_n_channels() channels = 4 bitmap = "" byte = 0 shift = 0 for j in range(pix.get_height()): offset = stride*j for i in range(pix.get_width()): if pixels[i*channels+offset] != "\0": byte += 1 << shift shift += 1 if shift > 7: bitmap += "%c" % byte byte = 0 shift = 0 if shift: bitmap += "%c" % byte byte = 0 shift = 0 #self.clipMask = cairo.ImageSurface.create_for_data(bytearray(bitmap), cairo.FORMAT_ARGB32, pix.get_width(), pix.get_height()) self.clearMask = Gdk.Rectangle() self.clearMask.x = 0 self.clearMask.y = 0 self.clearMask.width = 1200 self.clearMask.height = 800 self.pageOffset = 5 # offset the first page by this self.dropWidth = 5 # line thickness of the drop head self.dropWidthDIV2 = self.dropWidth//2 self.pixelsPerPitch = float(self.trackRect[0][3]-1)/(Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH) self.pixelsPerPitchDrum = float(self.trackRect[self.drumIndex][3]-1)/(Config.MAXIMUM_PITCH_DRUM - Config.MINIMUM_PITCH_DRUM ) self.pixelsPerTick = [0] + [ float(self.trackRect[0][2]-4)/(i*Config.TICKS_PER_BEAT) for i in range(1,Config.MAXIMUM_BEATS+1) ] import logging logging.error('> %r %r %r', self.pixelsPerPitch, self.pixelsPerPitchDrum, self.pixelsPerTick) self.alloced = False self.width = self.baseWidth = self.height = -1 self.waitingForAlloc = True self.scrollTo = None self.clickX = -1 self.set_size_request( self.width, self.height ) self.button1Down = False self.dragMode = None self.dropAt = -1 self.dropAtX = 0 self.visibleX = 0 self.visibleEndX = 0 self.add_events(Gdk.EventMask.POINTER_MOTION_MASK|Gdk.EventMask.POINTER_MOTION_HINT_MASK) self.connect( "size-allocate", self.size_allocated ) self.drawingArea.connect( "draw", self.draw ) self.connect( "button-press-event", self.handleButtonPress ) self.connect( "button-release-event", self.handleButtonRelease ) self.connect( "motion-notify-event", self.handleMotion )
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 handleGenerationSlider(self, adj): img = int(adj.value * 7)+1 self.geneSliderBoxImgTop.set_from_file( imagefile('complex' + str(img) + '.png'))
def __init__( self, noteDB, owner, adjustment ): gtk.EventBox.__init__( self ) self.noteDB = noteDB self.owner = owner self.adjustment = adjustment #adjustment.connect( "changed", self.adjustmentChanged ) adjustment.connect( "value-changed", self.adjustmentValue ) self.drawingArea = gtk.DrawingArea() self.drawingAreaDirty = False # is the drawingArea waiting to draw? self.add( self.drawingArea ) self.dirtyRectToAdd = gtk.gdk.Rectangle() # used by the invalidate_rect function self.selectedIds = [] self.displayedPage = -1 self.drumIndex = Config.NUMBER_OF_TRACKS-1 self.trackRect = Config.THUMBNAIL_TRACK_RECT self.thumbnail = {} self.thumbnailDirty = {} self.thumbnailDirtyRect = {} self.defaultwin = gtk.gdk.get_default_root_window() # used when creating pixmaps self.gc = gtk.gdk.GC( self.defaultwin ) colormap = self.drawingArea.get_colormap() self.bgColor = colormap.alloc_color( Config.TOOLBAR_BCK_COLOR, True, True ) self.lineColor = colormap.alloc_color( Config.THUMBNAIL_DRAG_COLOR, True, True ) self.displayedColor = colormap.alloc_color( Config.THUMBNAIL_DISPLAYED_COLOR, True, True ) self.selectedColor = colormap.alloc_color( Config.THUMBNAIL_SELECTED_COLOR, True, True ) # prepare thumbnail self.thumbnailBG = [] self.gc.foreground = self.bgColor for i in range(4): pix = gtk.gdk.pixbuf_new_from_file( imagefile('pageThumbnailBG%d.png' % i)) self.thumbnailBG.append( gtk.gdk.Pixmap( self.defaultwin, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) ) self.thumbnailBG[i].draw_rectangle( self.gc, True, 0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) self.thumbnailBG[i].draw_pixbuf( self.gc, pix, 0, 0, 0, 0, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT, gtk.gdk.RGB_DITHER_NONE ) # load clipmask pix = gtk.gdk.pixbuf_new_from_file(imagefile('pageThumbnailMask.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()): if pixels[i*channels+offset] != "\0": byte += 1 << shift shift += 1 if shift > 7: bitmap += "%c" % byte byte = 0 shift = 0 if shift: bitmap += "%c" % byte byte = 0 shift = 0 self.clipMask = gtk.gdk.bitmap_create_from_data( None, bitmap, pix.get_width(), pix.get_height() ) self.clearMask = gtk.gdk.Rectangle( 0, 0, 1200, 800 ) self.pageOffset = 5 # offset the first page by this self.dropWidth = 5 # line thickness of the drop head self.dropWidthDIV2 = self.dropWidth//2 self.pixelsPerPitch = float(self.trackRect[0][3]-1)/(Config.MAXIMUM_PITCH - Config.MINIMUM_PITCH) self.pixelsPerPitchDrum = float(self.trackRect[self.drumIndex][3]-1)/(Config.MAXIMUM_PITCH_DRUM - Config.MINIMUM_PITCH_DRUM ) self.pixelsPerTick = [0] + [ float(self.trackRect[0][2]-4)/(i*Config.TICKS_PER_BEAT) for i in range(1,Config.MAXIMUM_BEATS+1) ] import logging logging.error('> %r %r %r', self.pixelsPerPitch, self.pixelsPerPitchDrum, self.pixelsPerTick) self.alloced = False self.width = self.baseWidth = self.height = -1 self.waitingForAlloc = True self.scrollTo = None self.clickX = -1 self.set_size_request( self.width, self.height ) self.button1Down = False self.dragMode = None self.dropAt = -1 self.dropAtX = 0 self.visibleX = 0 self.visibleEndX = 0 self.add_events(gtk.gdk.POINTER_MOTION_MASK|gtk.gdk.POINTER_MOTION_HINT_MASK) self.connect( "size-allocate", self.size_allocated ) self.drawingArea.connect( "expose-event", self.draw ) self.connect( "button-press-event", self.handleButtonPress ) self.connect( "button-release-event", self.handleButtonRelease ) self.connect( "motion-notify-event", self.handleMotion )
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)