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 | |
parent | 146f6eefdb76494a1d8d9b033c64b3a686227225 (diff) | |
parent | 565712fda89907e74683d618dac006a1dbb6f061 (diff) |
Merge branch 'master' of git+ssh://amartin@dev.laptop.org/git/projects/tamtam
Diffstat (limited to 'Edit')
-rw-r--r-- | Edit/MainWindow.py | 26 | ||||
-rw-r--r-- | Edit/TrackInterface.py | 118 |
2 files changed, 134 insertions, 10 deletions
diff --git a/Edit/MainWindow.py b/Edit/MainWindow.py index 5fce403..e6d7118 100644 --- a/Edit/MainWindow.py +++ b/Edit/MainWindow.py @@ -256,7 +256,7 @@ class MainWindow( SubActivity ): #self.GUI["2XYSliderYAdjustment"] = gtk.Adjustment( 650, 500, 1000, 1, 1, 1 ) #self.GUI["2XYSlider"] = XYSlider( self.GUI["2XYSliderFixed"], self.GUI["2XYSliderButton"], self.GUI["2XYSliderXAdjustment"], self.GUI["2XYSliderYAdjustment"], True, True ) #self.GUI["2rightPanel"].pack_start( self.GUI["2XYSlider"], False, False, 0 ) - self.trackInterface = TrackInterface( self.noteDB, self ) + self.trackInterface = TrackInterface( self.noteDB, self, self.getScale ) self.noteDB.addListener( self.trackInterface, TrackInterfaceParasite, True ) self.trackInterface.set_size_request( -1, 713 ) self.GUI["2rightPanel"].pack_start( self.trackInterface, False, False, 0 ) @@ -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"] ) @@ -831,6 +835,9 @@ class MainWindow( SubActivity ): #else: # recordButton.hide() + def getScale(self): + return self.generationPanel.scale + def handleVolume( self, widget ): self._data["volume"] = round( widget.get_value() ) self.csnd.setMasterVolume(self._data["volume"]) @@ -1648,7 +1655,8 @@ class MainWindow( SubActivity ): return self.noteDB.updateNote( n.page, n.track, n.id, PARAMETER.DURATION, adjustedDuration) if onsetQuantized >= n.cs.onset and (onsetQuantized+2) <= (n.cs.onset + n.cs.duration): - return + self.noteDB.deleteNote(n.page, n.track, n.id) + #return csnote = CSoundNote(onset = 0, pitch = pitch, @@ -1709,7 +1717,8 @@ class MainWindow( SubActivity ): for n in self.noteDB.getNotesByTrack( csId[0], csId[1] ): if csId[3] < n.cs.onset and (csId[3] + newDuration) >= n.cs.onset: - newDuration = n.cs.onset - csId[3] + self.noteDB.deleteNote(n.page, n.track, n.id) + #newDuration = n.cs.onset - csId[3] break self.noteDB.updateNote( csId[0], csId[1], csId[2], PARAMETER.DURATION, newDuration) @@ -1727,7 +1736,8 @@ class MainWindow( SubActivity ): for n in self.noteDB.getNotesByTrack( self.csId[0], self.csId[1] ): if self.csId[3] < n.cs.onset and (self.csId[3] + newDuration) > n.cs.onset: - newDuration = n.cs.onset - self.csId[3] + self.noteDB.deleteNote(n.page, n.track, n.id) + #newDuration = n.cs.onset - self.csId[3] break self.noteDB.updateNote( self.csId[0], self.csId[1], self.csId[2], PARAMETER.DURATION, newDuration) 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) |