diff options
author | Oli <olivier.belanger@umontreal.ca> | 2007-06-27 20:05:15 (GMT) |
---|---|---|
committer | Oli <olivier.belanger@umontreal.ca> | 2007-06-27 20:05:15 (GMT) |
commit | 91d2892122e0019b55287beeb59367f058e42923 (patch) | |
tree | 4019b631167e148faa085cdba5295930070bd466 /Edit | |
parent | 7f9355bd8d346e916af98d7514d6887b6d0f2b6b (diff) |
brush tool
Diffstat (limited to 'Edit')
-rw-r--r-- | Edit/MainWindow.py | 12 | ||||
-rw-r--r-- | Edit/TrackInterface.py | 96 |
2 files changed, 104 insertions, 4 deletions
diff --git a/Edit/MainWindow.py b/Edit/MainWindow.py index a546a5f..b75f3a8 100644 --- a/Edit/MainWindow.py +++ b/Edit/MainWindow.py @@ -266,17 +266,21 @@ class MainWindow( SubActivity ): self.GUI["2toolPanel"].set_size_request( -1, toolPanelHeight ) # + + tool box self.GUI["2toolBox"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) - self.GUI["2toolBox"].set_size_request( 144, -1 ) + self.GUI["2toolBox"].set_size_request( 204, -1 ) self.GUI["2toolPointerButton"] = ImageRadioButton( None, Config.IMAGE_ROOT+"pointer.png", Config.IMAGE_ROOT+"pointerDown.png", backgroundFill = Config.BG_COLOR ) self.GUI["2toolPointerButton"].connect( "clicked", self.handleToolClick , "default" ) self.GUI["2toolBox"].pack_start( self.GUI["2toolPointerButton"] ) self.GUI["2toolPencilButton"] = ImageRadioButton( self.GUI["2toolPointerButton"], Config.IMAGE_ROOT+"pencil.png", Config.IMAGE_ROOT+"pencilDown.png", backgroundFill = Config.BG_COLOR ) self.GUI["2toolPencilButton"].connect( "clicked", self.handleToolClick , "draw" ) self.GUI["2toolBox"].pack_start( self.GUI["2toolPencilButton"] ) + self.GUI["2toolPencilButton"] = ImageRadioButton( self.GUI["2toolPointerButton"], Config.IMAGE_ROOT+"brush.png", Config.IMAGE_ROOT+"brushDown.png", backgroundFill = Config.BG_COLOR ) + self.GUI["2toolPencilButton"].connect( "clicked", self.handleToolClick , "paint" ) + self.GUI["2toolBox"].pack_start( self.GUI["2toolPencilButton"] ) + self.GUI["2toolPanel"].pack_start( self.GUI["2toolBox"], False, False ) self.GUI["2rightPanel"].pack_start( self.GUI["2toolPanel"], False ) # + + context box (for context sensitive buttons, nothing to do with CAIRO) - contextWidth = 674 + contextWidth = 594 self.GUI["2contextBox"] = formatRoundBox( RoundFixed(), Config.BG_COLOR ) self.GUI["2contextBox"].set_size_request( contextWidth, -1 ) self.GUI["2contextPrevButton"] = ImageButton( Config.IMAGE_ROOT+"arrowEditLeft.png", Config.IMAGE_ROOT+"arrowEditLeftDown.png", Config.IMAGE_ROOT+"arrowEditLeftOver.png", backgroundFill = Config.BG_COLOR ) @@ -338,9 +342,9 @@ class MainWindow( SubActivity ): self.GUI["2toolPanel"].pack_start( self.GUI["2contextBox"], False ) # + + transport box self.GUI["2transportBox"] = formatRoundBox( RoundHBox(), Config.BG_COLOR ) - self.GUI["2keyRecordButton"] = ImageToggleButton( Config.IMAGE_ROOT+"record2.png", Config.IMAGE_ROOT+"record2sel.png", Config.IMAGE_ROOT+"record2sel.png", backgroundFill = Config.BG_COLOR ) + self.GUI["2keyRecordButton"] = ImageToggleButton( Config.IMAGE_ROOT+"krecord.png", Config.IMAGE_ROOT+"krecordDown.png", Config.IMAGE_ROOT+"krecordOver.png", backgroundFill = Config.BG_COLOR ) self.GUI["2keyRecordButton"].connect("clicked", self.handleKeyboardRecordButton ) - self.GUI["2recordButton"] = ImageToggleButton( Config.IMAGE_ROOT+"record.png", Config.IMAGE_ROOT+"recordsel.png", Config.IMAGE_ROOT+"recordsel.png", backgroundFill = Config.BG_COLOR ) + self.GUI["2recordButton"] = ImageToggleButton( Config.IMAGE_ROOT+"record2.png", Config.IMAGE_ROOT+"record2Down.png", Config.IMAGE_ROOT+"record2Over.png", backgroundFill = Config.BG_COLOR ) self.GUI["2recordButton"].connect("clicked", self.handleAudioRecord ) self.GUI["2transportBox"].pack_start( self.GUI["2keyRecordButton"] ) self.GUI["2transportBox"].pack_start( self.GUI["2recordButton"] ) diff --git a/Edit/TrackInterface.py b/Edit/TrackInterface.py index 5db645d..5475d55 100644 --- a/Edit/TrackInterface.py +++ b/Edit/TrackInterface.py @@ -28,6 +28,7 @@ class INTERFACEMODE: DRAW = 1 PASTE_NOTES = 2 PASTE_TRACKS = 3 + PAINT = 4 class TrackInterfaceParasite: def __init__( self, noteDB, owner, note ): @@ -60,6 +61,7 @@ class TrackInterface( gtk.EventBox ): self.curPage = -1 # this isn't a real page at all! self.curBeats = 4 + self.painting = False self.selectedNotes = [ [] for i in range(Config.NUMBER_OF_TRACKS) ] @@ -278,6 +280,8 @@ class TrackInterface( gtk.EventBox ): if mode == "draw": self.interfaceMode = INTERFACEMODE.DRAW + elif mode == "paint": + self.interfaceMode = INTERFACEMODE.PAINT elif mode == "paste_notes": self.interfaceMode = INTERFACEMODE.PASTE_NOTES self.setCurrentAction("paste", self) @@ -385,6 +389,49 @@ class TrackInterface( gtk.EventBox ): TP.ProfileEnd( "TI::handleButtonPress" ) return + elif self.interfaceMode == INTERFACEMODE.PAINT: + self.painting = True + self.paintTrack = i + self.GRID = 3. + if i == self.drumIndex: + pitch = min( self.pixelsToPitchDrumFloor( self.clickLoc[1] - self.trackLimits[i][1] + Config.HIT_HEIGHT//2 )//Config.PITCH_STEP_DRUM, Config.NUMBER_OF_POSSIBLE_PITCHES_DRUM-1)*Config.PITCH_STEP_DRUM + Config.MINIMUM_PITCH_DRUM + if pitch < 24: + pitch = 24 + elif pitch > 48: + pitch = 48 + else: + pitch = pitch + else: + pitch = min( self.pixelsToPitchFloor( self.clickLoc[1] - self.trackLimits[i][1] + Config.NOTE_HEIGHT//2 ), Config.NUMBER_OF_POSSIBLE_PITCHES-1) + Config.MINIMUM_PITCH + if pitch < 24: + pitch = 24 + elif pitch > 48: + pitch = 48 + else: + pitch = pitch + onset = self.pixelsToTicksFloor( self.curBeats, self.clickLoc[0] - self.trackRect[i].x ) + onset = self.GRID * int(onset / self.GRID + 0.5) + self.pLastPos = onset + if i != self.drumIndex: + noteS = self.noteDB.getNotesByTrack(self.curPage, i) + for n in noteS: + if onset >= n.cs.onset and onset < (n.cs.onset + n.cs.duration): + self.noteDB.deleteNote(self.curPage, i, n.id) + + cs = CSoundNote( onset, + pitch, + 0.75, + 0.5, + 1, + i, + instrumentId = self.owner.getTrackInstrument(i).instrumentId ) + cs.pageId = self.curPage + id = self.noteDB.addNote( -1, self.curPage, i, cs ) + self.noteDB.updateNote(self.curPage, i, id, PARAMETER.DURATION, self.GRID) + n = self.noteDB.getNote( self.curPage, i, id, self ) + self.selectNotes( { i:[n] }, True ) + n.playSampleNote( False ) + self.curAction = True TP.ProfileEnd( "TI::handleButtonPress" ) @@ -392,6 +439,7 @@ class TrackInterface( gtk.EventBox ): def handleButtonRelease( self, widget, event ): if not self.clickButton: return # we recieved this event but were never clicked! (probably a popup window was open) self.clickButton = 0 + self.painting = False TP.ProfileBegin( "TI::handleButtonRelease" ) @@ -439,6 +487,54 @@ class TrackInterface( gtk.EventBox ): event.y = float(y) event.state = state + if self.painting: + i = self.paintTrack + curPos = self.pixelsToTicksFloor(self.curBeats, event.x - self.trackRect[i].x) + gridPos = self.GRID * int(curPos / self.GRID) + if gridPos >= self.curBeats * Config.TICKS_PER_BEAT: + return + if gridPos != self.pLastPos: + self.pLastPos = gridPos + if i == self.drumIndex: + pitch = min( self.pixelsToPitchDrumFloor( int(event.y) - self.trackLimits[i][1] + Config.HIT_HEIGHT//2 )//Config.PITCH_STEP_DRUM, Config.NUMBER_OF_POSSIBLE_PITCHES_DRUM-1)*Config.PITCH_STEP_DRUM + Config.MINIMUM_PITCH_DRUM + if pitch < 24: + pitch = 24 + elif pitch > 48: + pitch = 48 + else: + pitch = pitch + else: + pitch = min( self.pixelsToPitchFloor( int(event.y) - self.trackLimits[i][1] + Config.NOTE_HEIGHT//2 ), Config.NUMBER_OF_POSSIBLE_PITCHES-1) + Config.MINIMUM_PITCH + if pitch < 24: + pitch = 24 + elif pitch > 48: + pitch = 48 + else: + pitch = pitch + + onset = gridPos + if i != self.drumIndex: + noteS = self.noteDB.getNotesByTrack(self.curPage, i) + for n in noteS: + if onset >= n.cs.onset and onset < (n.cs.onset + n.cs.duration): + self.noteDB.deleteNote(self.curPage, i, n.id) + + cs = CSoundNote( onset, + pitch, + 0.75, + 0.5, + 1, + i, + instrumentId = self.owner.getTrackInstrument(i).instrumentId ) + cs.pageId = self.curPage + id = self.noteDB.addNote( -1, self.curPage, i, cs ) + self.noteDB.updateNote(self.curPage, i, id, PARAMETER.DURATION, self.GRID) + n = self.noteDB.getNote( self.curPage, i, id, self ) + self.selectNotes( { i:[n] }, True ) + n.playSampleNote( False ) + self.curAction = True + + TP.ProfileEnd( "TI::handleMotion::Common" ) if not self.clickButton and self.curAction != "paste": # we recieved this event but were never clicked! (probably a popup window was open) |