From 9ba0c8dc8ecb965894cdc9d12dfb9b83e8992fa8 Mon Sep 17 00:00:00 2001 From: Gonzalo Odiard Date: Tue, 15 Jan 2013 13:01:18 +0000 Subject: Ported more TamTamEdit code to Gtk3 Signed-off-by: Aaron Gordon --- diff --git a/Edit/HitInterface.py b/Edit/HitInterface.py index 2c3572d..84e0356 100644 --- a/Edit/HitInterface.py +++ b/Edit/HitInterface.py @@ -182,7 +182,7 @@ class HitInterface( NoteInterface ): #======================================================= # Draw - def draw( self, surface, gc, startX, stopX ): + def draw( self, surface, startX, stopX ): if stopX < self.imgX: return False # we don't need to draw and no one after us will draw if startX > self.imgX + self.imgWidth: return True # we don't need to draw, but maybe a later note does cxt = cairo.Context(surface) diff --git a/Edit/NoteInterface.py b/Edit/NoteInterface.py index 2547176..5e3da41 100644 --- a/Edit/NoteInterface.py +++ b/Edit/NoteInterface.py @@ -332,7 +332,7 @@ class NoteInterface: #======================================================= # Draw - def draw(self, surface, gc, startX, stopX ): + def draw(self, surface, startX, stopX): if stopX < self.imgX: return False # we don't need to draw and no one after us will draw if startX > self.imgX + self.imgWidth: return True # we don't need to draw, but maybe a later note does cxt = cairo.Context(surface) diff --git a/Edit/TrackInterface.py b/Edit/TrackInterface.py index 2e6e9b3..fbf8084 100644 --- a/Edit/TrackInterface.py +++ b/Edit/TrackInterface.py @@ -415,21 +415,21 @@ class TrackInterface( Gtk.EventBox ): if self.trackLimits[i][1] < event.y: continue handled = 0 - #notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) - #last = len(notes)-1 - #for n in range(last+1): - # if i == self.drumIndex and n < last: # check to see if the next hit overlaps this one - # if notes[n].getStartTick() == notes[n+1].getStartTick() and notes[n].getPitch() == notes[n+1].getPitch(): - # continue - # handled = notes[n].handleButtonPress( self, event ) - # if handled == 0: - # continue - # elif handled == 1: - # if not self.curAction: self.curAction = True # it was handled but no action was declared, set curAction to True anyway - # TP.ProfileEnd( "TI::handleButtonPress" ) - # return - # else: # all other options mean we can stop looking - # break + notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) + last = len(notes)-1 + for n in range(last+1): + if i == self.drumIndex and n < last: # check to see if the next hit overlaps this one + if notes[n].getStartTick() == notes[n+1].getStartTick() and notes[n].getPitch() == notes[n+1].getPitch(): + continue + handled = notes[n].handleButtonPress( self, event ) + if handled == 0: + continue + elif handled == 1: + if not self.curAction: self.curAction = True # it was handled but no action was declared, set curAction to True anyway + TP.ProfileEnd( "TI::handleButtonPress" ) + return + else: # all other options mean we can stop looking + break if self.interfaceMode == INTERFACEMODE.DRAW: if not handled or handled == -1: # event didn't overlap any notes, so we can draw @@ -450,10 +450,10 @@ class TrackInterface( Gtk.EventBox ): self.selectNotes( { i:[n] }, True ) n.playSampleNote( False ) - #noteS = self.noteDB.getNotesByTrack(self.curPage, i) - #for note in noteS: - # if note.cs.onset < snapOnset and (note.cs.onset + note.cs.duration) > snapOnset: - # self.noteDB.updateNote(self.curPage, i, note.id, PARAMETER.DURATION, snapOnset - note.cs.onset) + noteS = self.noteDB.getNotesByTrack(self.curPage, i) + for note in noteS: + if note.cs.onset < snapOnset and (note.cs.onset + note.cs.duration) > snapOnset: + self.noteDB.updateNote(self.curPage, i, note.id, PARAMETER.DURATION, snapOnset - note.cs.onset) if i != self.drumIndex: # switch to drag duration self.updateDragLimits() @@ -1157,13 +1157,13 @@ class TrackInterface( Gtk.EventBox ): if self.trackLimits[i][0] > event.y: break if self.trackLimits[i][1] < event.y: continue - #notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) - #handled = 0 - #for n in range(len(notes)): - # handled = notes[n].updateTooltip( self, event ) - # if handled == 0: continue - # elif handled == 1: return # event was handled - # else: break + notes = self.noteDB.getNotesByTrack( self.curPage, i, self ) + handled = 0 + for n in range(len(notes)): + handled = notes[n].updateTooltip( self, event ) + if handled == 0: continue + elif handled == 1: return # event was handled + else: break # note wasn't handled, could potentially draw a note if self.interfaceMode == INTERFACEMODE.DRAW: @@ -1187,7 +1187,7 @@ class TrackInterface( Gtk.EventBox ): # Drawing def draw( self, buf, noescape = True, timeout = 0 ): - print "Buf = " , buf + #print "Buf = " , buf #if not self.screenBufDirty[buf]: return True TP.ProfileBegin( "TrackInterface::draw" ) @@ -1201,7 +1201,7 @@ class TrackInterface( Gtk.EventBox ): beats = self.screenBufBeats[buf] pixmap = self.screenBuf[buf] - print "pixmap = ", pixmap + #print "pixmap = ", pixmap cxt = cairo.Context(pixmap) resume = self.screenBufResume[buf] @@ -1239,21 +1239,20 @@ class TrackInterface( Gtk.EventBox ): # draw notes #TP.ProfileBegin("TI::draw notes") - #notes = self.noteDB.getNotesByTrack( self.screenBufPage[buf], i, self ) - #for n in range( resume[2], len(notes) ): - # # check escape - # if not noescape and time.time() > timeout: - # resume[0] = i - # resume[2] = n - # TP.ProfilePause( "TrackInterface::draw" ) - # return False - # - # if not notes[n].draw( pixmap, self.gc, startX, stopX ): break + notes = self.noteDB.getNotesByTrack( self.screenBufPage[buf], i, self ) + for n in range( resume[2], len(notes) ): + # check escape + if not noescape and time.time() > timeout: + resume[0] = i + resume[2] = n + TP.ProfilePause( "TrackInterface::draw" ) + return False + if not notes[n].draw(pixmap, startX, stopX): break # TP.ProfileEnd("TI::draw notes") # finished a track, reset the resume values for the next one - #resume[1] = 0 - #resume[2] = 0 + resume[1] = 0 + resume[2] = 0 # drum track if stopY > self.trackLimits[self.drumIndex][0]: @@ -1287,7 +1286,7 @@ class TrackInterface( Gtk.EventBox ): resume[2] = n TP.ProfilePause( "TrackInterface::draw" ) return False - #if not notes[n].draw( pixmap, self.gc, startX, stopX ): break + if not notes[n].draw(pixmap, startX, stopX ): break self.screenBufDirty[buf] = False diff --git a/Edit/TuneInterface.py b/Edit/TuneInterface.py index ecd46f8..7a94080 100644 --- a/Edit/TuneInterface.py +++ b/Edit/TuneInterface.py @@ -76,11 +76,14 @@ class TuneInterfaceParasite: self.width = width self.owner.invalidate_thumbnail( self.note.page, x, y, width, 1 ) - def draw( self, win, gc, startX, stopX ): + def draw( self, win, startX, stopX ): if stopX < self.x: return False # we don't need to draw and no one after us will draw if startX > self.endx: return True # we don't need to draw, but maybe a later note does - win.draw_line( gc, self.x, self.y, self.endx, self.y ) + cxt = cairo.Context(win) + cxt.move_to(self.x, self.y) + cxt.line_to(self.endx, self.y) + cxt.stroke() return True # we drew something @@ -94,6 +97,9 @@ class TuneInterface( Gtk.EventBox ): def __init__( self, noteDB, owner, adjustment ): Gtk.EventBox.__init__( self ) + + self.num = 0 + self.noteDB = noteDB self.owner = owner self.adjustment = adjustment @@ -545,13 +551,17 @@ class TuneInterface( Gtk.EventBox ): stopX = rect.x + rect.width stopY = rect.y + rect.height + cxt = cairo.Context(pixmap) # draw background - print self.thumbnailBG[self.noteDB.getPage(id).color] - pixmap.draw_drawable( self.gc, self.thumbnailBG[self.noteDB.getPage(id).color], startX, startY, startX, startY, rect.width, rect.height+1 ) + cxt.set_source_surface(self.thumbnailBG[self.noteDB.getPage(id).color], startX, startY) + cxt.paint() # draw regular tracks - self.gc.foreground = self.lineColor - self.gc.set_line_attributes( 1, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) + cxt.set_source_rgb(*gdk_color_to_cairo(self.lineColor)) + cxt.set_line_width(1) + cxt.set_line_cap(cairo.LINE_CAP_BUTT) + cxt.set_line_join(cairo.LINE_JOIN_MITER) + #self.gc.set_line_attributes( 1, gtk.gdk.LINE_SOLID, gtk.gdk.CAP_BUTT, gtk.gdk.JOIN_MITER ) for i in range(self.drumIndex): if startY >= self.trackRect[i+1][1]: continue if stopY < self.trackRect[i][1]: break @@ -559,16 +569,20 @@ class TuneInterface( Gtk.EventBox ): # draw notes notes = self.noteDB.getNotesByTrack( id, i, self ) for n in range( len(notes) ): - if not notes[n].draw( pixmap, self.gc, startX, stopX ): break + if not notes[n].draw( pixmap, startX, stopX ): break + # drum track if stopY > self.trackRect[self.drumIndex][0]: # draw notes notes = self.noteDB.getNotesByTrack( id, self.drumIndex, self ) for n in range( len(notes) ): - if not notes[n].draw( pixmap, self.gc, startX, stopX ): break + if not notes[n].draw( pixmap, startX, stopX ): break self.thumbnailDirty[id] = False - + #f = open("test%d.png" % self.num, "w") + #pixmap.write_to_png(f) + #f.close() + #self.num += 1 def draw( self, drawingArea, cr): @@ -592,7 +606,6 @@ class TuneInterface( Gtk.EventBox ): x = self.pageOffset endx = x + Config.PAGE_THUMBNAIL_WIDTH - print self.noteDB.getTune() for pageId in self.noteDB.getTune(): if endx < startX: x = endx @@ -602,30 +615,36 @@ class TuneInterface( Gtk.EventBox ): # draw thumbnail if self.thumbnailDirty[pageId]: - self.gc.set_clip_origin( 0, 0 ) + #self.gc.set_clip_origin( 0, 0 ) self.drawThumbnail( pageId, self.thumbnail[pageId], self.thumbnailDirtyRect[pageId] ) - self.gc.set_clip_origin( x, self.pageY ) - drawingArea.window.draw_drawable( self.gc, self.thumbnail[pageId], 0, 0, x, self.pageY, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) + #self.gc.set_clip_origin( x, self.pageY ) + print "Coordinates ", x, self.pageY + cr.set_source_surface(self.thumbnail[pageId], x, self.pageY) + cr.paint() # draw border if necessary if pageId == self.displayedPage: # displayed page border - self.gc.set_function( gtk.gdk.INVERT ) + #self.gc.set_function( gtk.gdk.INVERT ) for i in range(Config.NUMBER_OF_TRACKS): if tracks[i]: - drawingArea.window.draw_rectangle( self.gc, True, x + self.trackRect[i][0], self.pageY + self.trackRect[i][1], self.trackRect[i][2], self.trackRect[i][3] ) - self.gc.set_function( gtk.gdk.COPY ) - self.gc.foreground = self.displayedColor - self.gc.set_clip_origin( x - Config.PAGE_THUMBNAIL_WIDTH, self.pageY ) - drawingArea.window.draw_rectangle( self.gc, True, x, self.pageY, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) + cr.rectangle(x + self.trackRect[i][0], self.pageY + self.trackRect[i][1], self.trackRect[i][2], self.trackRect[i][3] ) + cr.stroke() + #self.gc.set_function( gtk.gdk.COPY ) + cr.set_source_rgb(*gdk_color_to_cairo(self.displayedColor)) + #self.gc.set_clip_origin( x - Config.PAGE_THUMBNAIL_WIDTH, self.pageY ) + cr.rectangle(x, self.pageY, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT) + cr.stroke() elif pageId in self.selectedIds: # selected page border - self.gc.set_function( gtk.gdk.INVERT ) + #self.gc.set_function( gtk.gdk.INVERT ) for i in range(Config.NUMBER_OF_TRACKS): if tracks[i]: - drawingArea.window.draw_rectangle( self.gc, True, x + self.trackRect[i][0], self.pageY + self.trackRect[i][1], self.trackRect[i][2], self.trackRect[i][3] ) - self.gc.set_function( gtk.gdk.COPY ) - self.gc.foreground = self.selectedColor - self.gc.set_clip_origin( x - Config.PAGE_THUMBNAIL_WIDTH, self.pageY ) - drawingArea.window.draw_rectangle( self.gc, True, x, self.pageY, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT ) + cr.rectangle(x + self.trackRect[i][0], self.pageY + self.trackRect[i][1], self.trackRect[i][2], self.trackRect[i][3]) + cr.fill() + #self.gc.set_function( gtk.gdk.COPY ) + cr.set_source_rgb(*gdk_color_to_cairo(self.selectedColor)) + #self.gc.set_clip_origin( x - Config.PAGE_THUMBNAIL_WIDTH, self.pageY ) + cr.rectangle(x, self.pageY, Config.PAGE_THUMBNAIL_WIDTH, Config.PAGE_THUMBNAIL_HEIGHT) + cr.stroke() x += Config.PAGE_THUMBNAIL_WIDTH diff --git a/TamTamEdit.py b/TamTamEdit.py index 512c5bf..fc4973d 100644 --- a/TamTamEdit.py +++ b/TamTamEdit.py @@ -145,7 +145,7 @@ class TamTamEdit(activity.Activity): csnd.connect(False) csnd.destroy() - gtk.main_quit() + Gtk.main_quit() # No more dir created by TamTam def ensure_dir(self, dir, perms=0777, rw=os.R_OK | os.W_OK): -- cgit v0.9.1