Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/Edit
diff options
context:
space:
mode:
authorOli <olivier.belanger@umontreal.ca>2007-08-21 04:29:06 (GMT)
committer Oli <olivier.belanger@umontreal.ca>2007-08-21 04:29:06 (GMT)
commit590fa7931ed2995a35ce54cc73b535828c00b167 (patch)
tree6ef6a684efe077844ba3bd3e62b5f0f5dd4f11e0 /Edit
parent6e89806275673d7785aab0e0a44355eee678aea2 (diff)
pointer, draw and paint now working
Diffstat (limited to 'Edit')
-rw-r--r--Edit/EditToolbars.py109
-rw-r--r--Edit/MainWindow.py2
-rw-r--r--Edit/TrackInterface.py86
3 files changed, 121 insertions, 76 deletions
diff --git a/Edit/EditToolbars.py b/Edit/EditToolbars.py
index 24b0ab2..3b98449 100644
--- a/Edit/EditToolbars.py
+++ b/Edit/EditToolbars.py
@@ -89,7 +89,7 @@ class mainToolbar(gtk.Toolbar):
self.drawButton.connect('toggled', self.edit.handleToolClick, 'draw')
self.insert(self.drawButton, -1)
self.drawButton.show()
-
+
#Paint button
self._paintPalette = paintPalette(_('Paint Tool'), self.edit)
self.paintButton = RadioToolButton('edit-brush', group = self.pointerButton)
@@ -97,7 +97,7 @@ class mainToolbar(gtk.Toolbar):
self.paintButton.connect('toggled', self.edit.handleToolClick, 'paint')
self.insert(self.paintButton, -1)
self.paintButton.show()
-
+
_insertSeparator(4)
#Duplicate button
@@ -179,13 +179,14 @@ class pointerPalette(Palette):
self.edit = edit
self.pointerBox = gtk.VBox()
-
+
self.snapGridHBox = gtk.HBox()
self.snapGridImage = gtk.Image()
self.snapGridImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/grid.svg')
self.snapGridBox = BigComboBox()
self.snapGridBox.connect('changed', self.handleSnapGrid)
- durs = [_('3'), _('6'), _('12'), _('24'), _('48')]
+ self.gridDurs = [1, 2, 3, 4, 6, 12, 24]
+ durs = [_('1/12'), _('1/6'), _('1/4'), _('1/3'), _('1/2'), _('1'), _('2') ]
for dur in durs:
self.snapGridBox.append_item(durs.index(dur),dur)
self.snapGridBox.set_active(0)
@@ -196,15 +197,15 @@ class pointerPalette(Palette):
self.pointerBox.show_all()
self.set_content(self.pointerBox)
-
- def handleNoteDur(self, widget):
+
pass
#self.noteDur = widget.props.value
-
+
def handleSnapGrid(self, widget):
- pass
- #self.edit.trackInterface.setGrid(int(widget.props.value))
-
+ data = widget.props.value
+ grid = int(self.gridDurs[data])
+ self.edit.trackInterface.setPointerGrid(grid)
+
class drawPalette(Palette):
def __init__(self, label, edit):
Palette.__init__(self, label)
@@ -212,13 +213,14 @@ class drawPalette(Palette):
self.edit = edit
self.drawBox = gtk.VBox()
-
+
self.snapGridHBox = gtk.HBox()
self.snapGridImage = gtk.Image()
self.snapGridImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/grid.svg')
self.snapGridBox = BigComboBox()
self.snapGridBox.connect('changed', self.handleSnapGrid)
- durs = [_('3'), _('6'), _('12'), _('24'), _('48')]
+ self.gridDurs = [1, 2, 3, 4, 6, 12, 24]
+ durs = [_('1/12'), _('1/6'), _('1/4'), _('1/3'), _('1/2'), _('1'), _('2') ]
for dur in durs:
self.snapGridBox.append_item(durs.index(dur),dur)
self.snapGridBox.set_active(0)
@@ -229,15 +231,15 @@ class drawPalette(Palette):
self.drawBox.show_all()
self.set_content(self.drawBox)
-
- def handleNoteDur(self, widget):
+
pass
#self.noteDur = widget.props.value
-
+
def handleSnapGrid(self, widget):
- pass
- #self.edit.trackInterface.setGrid(int(widget.props.value))
-
+ data = widget.props.value
+ grid = int(self.gridDurs[data])
+ self.edit.trackInterface.setDrawGrid(grid)
+
class paintPalette(Palette):
def __init__(self, label, edit):
Palette.__init__(self, label)
@@ -251,22 +253,24 @@ class paintPalette(Palette):
self.noteDurImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/notedur.svg')
self.noteDurBox = BigComboBox()
self.noteDurBox.connect('changed', self.handleNoteDur)
- durs = [_('1/2'), _('1/4'), _('1/8'), _('1/16'), _('1/32')]
- for dur in durs:
- self.noteDurBox.append_item(durs.index(dur),dur)
- self.noteDurBox.set_active(0)
+ self.noteDurs = [1, 2, 3, 4, 6, 12, 24]
+ self.durs = [_('1/12'), _('1/6'), _('1/4'), _('1/3'), _('1/2'), _('1'), _('2') ]
+ for dur in self.durs:
+ self.noteDurBox.append_item(self.durs.index(dur),dur)
+ self.noteDurBox.set_active(2)
self.noteDurHBox.pack_start(self.noteDurImage, False, False, padding = 5)
self.noteDurHBox.pack_start(self.noteDurBox, False, False, padding = 5)
-
+
self.snapGridHBox = gtk.HBox()
self.snapGridImage = gtk.Image()
self.snapGridImage.set_from_file(Config.TAM_TAM_ROOT + '/icons/grid.svg')
self.snapGridBox = BigComboBox()
self.snapGridBox.connect('changed', self.handleSnapGrid)
- durs = [_('3'), _('6'), _('12'), _('24'), _('48')]
+ self.gridDurs = [1, 2, 3, 4, 6, 12, 24]
+ durs = [_('1/12'), _('1/6'), _('1/4'), _('1/3'), _('1/2'), _('1'), _('2')]
for dur in durs:
self.snapGridBox.append_item(durs.index(dur),dur)
- self.snapGridBox.set_active(0)
+ self.snapGridBox.set_active(2)
self.snapGridHBox.pack_start(self.snapGridImage, False, False, padding = 5)
self.snapGridHBox.pack_start(self.snapGridBox, False, False, padding = 5)
@@ -275,15 +279,28 @@ class paintPalette(Palette):
self.paintBox.show_all()
self.set_content(self.paintBox)
-
+
+ def resizeNoteDur(self):
+ oldActive = self.noteDurBox.get_active()
+ len = self.snapGridBox.get_active()
+ self.noteDurBox.remove_all()
+ for dur in self.durs[0:len+1]:
+ self.noteDurBox.append_item(self.durs.index(dur), dur)
+ if oldActive <= len:
+ self.noteDurBox.set_active(oldActive)
+ else:
+ self.noteDurBox.set_active(len)
+
def handleNoteDur(self, widget):
- pass
- #self.noteDur = widget.props.value
-
+ data = widget.props.value
+ noteDur = int(self.noteDurs[data])
+ self.edit.trackInterface.setPaintNoteDur(noteDur)
+
def handleSnapGrid(self, widget):
- pass
- #data = processinsomeway(widget.props.value)
- #self.edit.trackInterface.setGrid(data)
+ data = widget.props.value
+ grid = int(self.gridDurs[data])
+ self.edit.trackInterface.setPaintGrid(grid)
+ self.resizeNoteDur()
class volumeTempoPalette(Palette):
def __init__(self, label, edit):
@@ -461,9 +478,9 @@ class generationPalette(Palette):
shift = 0
self.sampleNoteMask = gtk.gdk.bitmap_create_from_data( None, bitmap, pix.get_width(), pix.get_height() )
self.sampleNoteMask.endOffset = pix.get_width()-3
-
+
colormap = self.previewDA.get_colormap()
- self.colors = { "Beat_Line": colormap.alloc_color( "#959595", True, True ),
+ self.colors = { "Beat_Line": colormap.alloc_color( "#959595", True, True ),
"Note_Border": colormap.alloc_color( Config.BG_COLOR, True, True ),
"Note_Fill": colormap.alloc_color( Config.FG_COLOR, True, True ) }
@@ -530,7 +547,7 @@ class generationPalette(Palette):
############ generate a preview melody ##############
def previewGeneratorTemp(self, widget, parameters):
self.previewGenerator(parameters)
-
+
def previewGenerator(self, parameters):
makeRythm = GenerationRythm()
makePitch = GenerationPitch(parameters.pattern)
@@ -575,33 +592,33 @@ class generationPalette(Palette):
elif len( onsetList ) == 1:
durationSequence.append( ( barLength - onsetList[0] ) * Utils.prob2( table_duration ))
return durationSequence
-
+
def parametersChanged( self ):
if not self.drawingPreview:
self.drawPreview()
else:
self.parametersDirty = True
-
+
def drawPreview( self, force = False ):
if self.drawingPreview and not force:
return # should never happen
-
+
notes, beats = self.previewGenerator( self.getGenerationParameters() )
self.parametersDirty = False
- if force:
+ if force:
if self.drawingPreview:
self.predrawIdleAbort = True
self._idleDraw( notes, beats, True, True )
- else:
+ else:
self.drawingPreview = True
gobject.idle_add( self._idleDraw, notes, beats, True, False )
-
+
def _idleDraw( self, notes, beats, fresh, force ):
if self.predrawIdleAbort and not force:
self.predrawIdleAbort = False
return False
-
+
pixmap = self.predrawBuffer[self.predrawTarget]
if fresh:
@@ -621,7 +638,7 @@ class generationPalette(Palette):
if force: N = len(notes)
else: N = min( 3, len( notes ) ) # adjust this value to get a reasonable response
-
+
self.gc.set_clip_mask( self.sampleNoteMask )
for i in range( N ): # draw N notes
note = notes.pop()
@@ -673,14 +690,14 @@ class generationPalette(Palette):
self.drawPreview( True )
- def handlePreviewExpose( self, widget, event ):
+ def handlePreviewExpose( self, widget, event ):
widget.window.draw_drawable( self.gc, self.predrawBuffer[not self.predrawTarget], event.area.x, event.area.y, event.area.x, event.area.y, event.area.width, event.area.height )
def ticksToPixels( self, beats, ticks ):
return int(round( ticks * self.pixelsPerTick[beats] ))
def pitchToPixels( self, pitch ):
return int(round( ( Config.MAXIMUM_PITCH - pitch ) * self.pixelsPerPitch ))
-
+
class propertiesPalette(Palette):
def __init__(self, label, edit):
@@ -724,7 +741,7 @@ class propertiesPalette(Palette):
self.pageColorComboBox.connect('changed', self.handleColor)
self.pageColorBox.pack_start(self.pageColorLabel, False, False, padding = 5)
self.pageColorBox.pack_end(self.pageColorComboBox, False, False, padding = 55)
-
+
self.pageSeparator = gtk.HSeparator()
self.pageSeparator.set_size_request(20, -1)
diff --git a/Edit/MainWindow.py b/Edit/MainWindow.py
index eedc3ff..0d66f68 100644
--- a/Edit/MainWindow.py
+++ b/Edit/MainWindow.py
@@ -73,7 +73,7 @@ class MainWindow( SubActivity ):
self.drumIndex = Config.NUMBER_OF_TRACKS - 1
#second instrument for melodic tracks
- self.trackInstrument2Default = [ Config.INSTRUMENTS["harmonica"], None, Config.INSTRUMENTS["rhodes"], None]
+ self.trackInstrument2Default = [ None, None, None, None]
self.trackInstrument2 = self.trackInstrument2Default[:]
self._data['volume'] = Config.DEFAULT_VOLUME
diff --git a/Edit/TrackInterface.py b/Edit/TrackInterface.py
index 0e35f92..45519de 100644
--- a/Edit/TrackInterface.py
+++ b/Edit/TrackInterface.py
@@ -65,6 +65,10 @@ class TrackInterface( gtk.EventBox ):
self.curPage = -1 # this isn't a real page at all!
self.curBeats = 4
self.painting = False
+ self.pointerGrid = 1
+ self.drawGrid = Config.DEFAULT_GRID
+ self.paintGrid = Config.DEFAULT_GRID
+ self.paintNoteDur = Config.DEFAULT_GRID
self.selectedNotes = [ [] for i in range(Config.NUMBER_OF_TRACKS) ]
@@ -225,7 +229,7 @@ class TrackInterface( gtk.EventBox ):
self.screenBufBeats[self.preScreen] = value
self.invalidate_rect( 0, 0, self.width, self.height, page )
self.predrawPage()
-
+
#=======================================================
# Module Interface
@@ -342,33 +346,39 @@ class TrackInterface( gtk.EventBox ):
def size_allocate( self, widget, allocation ):
self.alloc = allocation
- width = allocation.width
- height = allocation.height
+ width = allocation.width
+ height = allocation.height
- self.drawingArea.set_size_request( width, height )
+ self.drawingArea.set_size_request( width, height )
if self.window != None:
self.invalidate_rect( 0, 0, width, height, self.curPage, False )
+ def setPointerGrid(self, value):
+ self.pointerGrid = value
+
+ def setDrawGrid(self, value):
+ self.drawGrid = value
+
+ def setPaintGrid(self, value):
+ self.paintGrid = value
+
+ def setPaintNoteDur(self, value):
+ self.paintNoteDur = value
+
def handleButtonPress( self, widget, event ):
TP.ProfileBegin( "TI::handleButtonPress" )
self.clickButton = event.button
- if event.button != 1:
- print "Should bring up some note parameters or something!"
- #self.noteParameters = NoteParametersWindow( self.trackDictionary, self.getNoteParameters )
- #self.setCurrentAction( "noteParameters", False )
- TP.ProfileEnd( "TI::handleButtonPress" )
- return
-
if event.type == gtk.gdk._2BUTTON_PRESS: self.buttonPressCount = 2
elif event.type == gtk.gdk._3BUTTON_PRESS: self.buttonPressCount = 3
else: self.buttonPressCount = 1
self.clickLoc = [ int(event.x), int(event.y) ]
+
if self.curAction == "paste":
self.doPaste()
self.setCurrentAction("block-track-select")
@@ -407,7 +417,9 @@ class TrackInterface( gtk.EventBox ):
if not handled or handled == -1: # event didn't overlap any notes, so we can draw
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
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
- cs = CSoundNote( self.pixelsToTicksFloor( self.curBeats, self.clickLoc[0] - self.trackRect[i].x ),
+ onset = self.pixelsToTicksFloor( self.curBeats, self.clickLoc[0] - self.trackRect[i].x)
+ snapOnset = self.drawGrid * int(onset / float(self.drawGrid) + 0.5)
+ cs = CSoundNote( snapOnset,
pitch,
0.75,
0.5,
@@ -419,6 +431,12 @@ class TrackInterface( gtk.EventBox ):
n = self.noteDB.getNote( self.curPage, i, id, self )
self.selectNotes( { i:[n] }, True )
n.playSampleNote( False )
+
+ noteS = self.noteDB.getNotesByTrack(self.curPage, i)
+ for n in noteS:
+ if n.cs.onset < snapOnset and (n.cs.onset + n.cs.duration) > snapOnset:
+ self.noteDB.updateNote(self.curPage, i, n.id, PARAMETER.DURATION, snapOnset - n.cs.onset)
+
if i != self.drumIndex: # switch to drag duration
self.updateDragLimits()
self.clickLoc[0] += self.ticksToPixels( self.curBeats, 1 )
@@ -433,8 +451,7 @@ class TrackInterface( gtk.EventBox ):
self.scale = self.getScale()
self.painting = True
self.paintTrack = i
- self.GRID = Config.DEFAULT_GRID
- if i == self.drumIndex:
+ 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
@@ -442,7 +459,7 @@ class TrackInterface( gtk.EventBox ):
pitch = 48
else:
pitch = pitch
- else:
+ 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
@@ -460,14 +477,19 @@ class TrackInterface( gtk.EventBox ):
pitch = nearestPit+36
onset = self.pixelsToTicksFloor( self.curBeats, self.clickLoc[0] - self.trackRect[i].x )
- onset = self.GRID * int(onset / self.GRID + 0.5)
+ onset = self.paintGrid * int(onset / self.paintGrid + 0.5)
self.pLastPos = onset
if i != self.drumIndex:
noteS = self.noteDB.getNotesByTrack(self.curPage, i)
+ ids = []
+ stream = []
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)
-
+ if n.cs.onset >= onset and n.cs.onset < (onset + self.paintNoteDur):
+ ids.append(n.id)
+ if len(ids):
+ stream += [self.curPage, i, len(ids)] + ids
+ self.noteDB.deleteNotes( stream + [-1] )
+
cs = CSoundNote( int(onset),
pitch,
0.75,
@@ -477,7 +499,7 @@ class TrackInterface( gtk.EventBox ):
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)
+ self.noteDB.updateNote(self.curPage, i, id, PARAMETER.DURATION, self.paintNoteDur)
n = self.noteDB.getNote( self.curPage, i, id, self )
self.selectNotes( { i:[n] }, True )
n.playSampleNote( False )
@@ -540,12 +562,12 @@ class TrackInterface( gtk.EventBox ):
if self.painting:
i = self.paintTrack
curPos = self.pixelsToTicksFloor(self.curBeats, event.x - self.trackRect[i].x)
- gridPos = self.GRID * int(curPos / self.GRID)
+ gridPos = self.paintGrid * int(curPos / self.paintGrid + 0.5)
if gridPos >= self.curBeats * Config.TICKS_PER_BEAT:
return
if gridPos != self.pLastPos:
- self.pLastPos = gridPos
- if i == self.drumIndex:
+ 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
@@ -553,7 +575,7 @@ class TrackInterface( gtk.EventBox ):
pitch = 48
else:
pitch = pitch
- else:
+ 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
@@ -572,10 +594,15 @@ class TrackInterface( gtk.EventBox ):
onset = gridPos
if i != self.drumIndex:
noteS = self.noteDB.getNotesByTrack(self.curPage, i)
+ ids = []
+ stream = []
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)
-
+ if n.cs.onset >= onset and n.cs.onset < (onset + self.paintNoteDur):
+ ids.append(n.id)
+ if len(ids):
+ stream += [self.curPage, i, len(ids)] + ids
+ self.noteDB.deleteNotes( stream + [-1] )
+
cs = CSoundNote( int(onset),
pitch,
0.75,
@@ -585,7 +612,7 @@ class TrackInterface( gtk.EventBox ):
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)
+ self.noteDB.updateNote(self.curPage, i, id, PARAMETER.DURATION, self.paintNoteDur)
n = self.noteDB.getNote( self.curPage, i, id, self )
self.selectNotes( { i:[n] }, True )
n.playSampleNote( False )
@@ -801,7 +828,8 @@ class TrackInterface( gtk.EventBox ):
def noteDragOnset( self, event ):
do = self.pixelsToTicks( self.curBeats, event.x - self.clickLoc[0] )
do = min( self.dragLimits[0][1], max( self.dragLimits[0][0], do ) )
-
+ do = self.pointerGrid * int(do / self.pointerGrid)
+
if do != self.lastDO:
self.lastDO = do
stream = []