diff options
author | amartin <olpc@xo-00-CE-12.localdomain> | 2007-06-28 21:25:51 (GMT) |
---|---|---|
committer | amartin <olpc@xo-00-CE-12.localdomain> | 2007-06-28 21:25:51 (GMT) |
commit | 79f52b3e1696d345cc2ecdc1235f7c830a5a2fa6 (patch) | |
tree | 5d207a3952c4442dc9a9c039a098a74a612902cc /Edit/TrackInterface.py | |
parent | 146f6eefdb76494a1d8d9b033c64b3a686227225 (diff) | |
parent | 565712fda89907e74683d618dac006a1dbb6f061 (diff) |
Merge branch 'master' of git+ssh://amartin@dev.laptop.org/git/projects/tamtam
Diffstat (limited to 'Edit/TrackInterface.py')
-rw-r--r-- | Edit/TrackInterface.py | 118 |
1 files changed, 116 insertions, 2 deletions
diff --git a/Edit/TrackInterface.py b/Edit/TrackInterface.py index f517b1d..5b4780e 100644 --- a/Edit/TrackInterface.py +++ b/Edit/TrackInterface.py @@ -14,7 +14,7 @@ from Edit.MainWindow import CONTEXT from Util.NoteDB import PARAMETER from Util.CSoundNote import CSoundNote - +from Generation.GenerationConstants import GenerationConstants from Util.Profiler import TP class SELECTNOTES: @@ -30,6 +30,7 @@ class INTERFACEMODE: DRAW = 1 PASTE_NOTES = 2 PASTE_TRACKS = 3 + PAINT = 4 class TrackInterfaceParasite: def __init__( self, noteDB, owner, note ): @@ -43,11 +44,12 @@ class TrackInterfaceParasite: class TrackInterface( gtk.EventBox ): - def __init__( self, noteDB, owner ): + def __init__( self, noteDB, owner, getScaleFunction ): gtk.EventBox.__init__( self ) self.noteDB = noteDB self.owner = owner + self.getScale = getScaleFunction self.drawingArea = gtk.DrawingArea() self.drawingAreaDirty = False # are we waiting to draw? @@ -62,6 +64,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) ] @@ -316,6 +319,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) @@ -423,6 +428,59 @@ class TrackInterface( gtk.EventBox ): TP.ProfileEnd( "TI::handleButtonPress" ) return + elif self.interfaceMode == INTERFACEMODE.PAINT: + self.scale = self.getScale() + 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 + + minDiff = 100 + for pit in GenerationConstants.SCALES[self.scale]: + diff = abs(pitch-(pit+36)) + if diff < minDiff: + minDiff = diff + nearestPit = pit + pitch = nearestPit+36 + + 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" ) @@ -430,6 +488,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" ) @@ -477,6 +536,61 @@ 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 + minDiff = 100 + for pit in GenerationConstants.SCALES[self.scale]: + diff = abs(pitch-(pit+36)) + if diff < minDiff: + minDiff = diff + nearestPit = pit + pitch = nearestPit+36 + + 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) |