diff options
author | james <james@loggerhead.localdomain> | 2006-12-11 23:20:52 (GMT) |
---|---|---|
committer | james <james@loggerhead.localdomain> | 2006-12-11 23:20:52 (GMT) |
commit | 7672416488924e1814d778c99b9ca575ae9a70c7 (patch) | |
tree | af7812d7d27b331cee4dc44d6fe30fcfc135a754 /GUI/Core/MainWindow.py | |
parent | d8237e11e4f4741bc1b6befc1c7f59c7144ae37c (diff) |
stuff done in the car to boston
Diffstat (limited to 'GUI/Core/MainWindow.py')
-rw-r--r-- | GUI/Core/MainWindow.py | 152 |
1 files changed, 70 insertions, 82 deletions
diff --git a/GUI/Core/MainWindow.py b/GUI/Core/MainWindow.py index aee78bc..9ce2b60 100644 --- a/GUI/Core/MainWindow.py +++ b/GUI/Core/MainWindow.py @@ -86,14 +86,10 @@ class MainWindow( gtk.EventBox ): self._data['track_inst'] = track_inst + [CSoundConstants.FLUTE] * (Constants.NUMBER_OF_TRACKS - len( track_inst) ) #{ pageId: { [track 0 = note list], [track 2 = note list], ... ] } - self._data['page_notes'] = {} - self._data['page_ticks'] = {} - self._data['page_beats'] = {} - for r in range(40): - self._data['page_notes'][r] = [[] for n in range( Constants.NUMBER_OF_TRACKS ) ] - self._data['page_beats'][r] = 4 - self._data['page_ticks'][r] = 4 * 12 - #{ pageId: ticks } + npages = 40 + nbeats = 4 + + self._data['page_beats'] = [nbeats for p in range(npages)] self._data['tempo'] = Constants.DEFAULT_TEMPO self._data['tune'] = [] self._data['notebin'] = [] @@ -141,20 +137,6 @@ class MainWindow( gtk.EventBox ): self.mainWindowBox.pack_start( self.trackPagesBox ) self.add( self.mainWindowBox ) - #to update mainView's contents when window gets resized - #TODO: is this the right way to do this? - - def initialize( ): - # Volume initialisation for Csound. - CSoundClient.setMasterVolume( self.getVolume() ) - - for pageId in range( GUIConstants.NUMBER_OF_PAGE_BANK_ROWS * GUIConstants.NUMBER_OF_PAGE_BANK_COLUMNS ): - self.pageBankView.addPage( pageId, False ) - - for tid in range(Constants.NUMBER_OF_TRACKS): - self.handleInstrumentChanged( ( tid, self._data['track_inst'][tid] ) ) - - # contains TAM-TAM and OLPC labels, as well as the volume and tempo sliders def setupGlobalControls( ): self.globalControlsFrame = gtk.Frame() @@ -311,7 +293,7 @@ class MainWindow( gtk.EventBox ): # playback params self.playing = False - self.playingTune = False + self.playSource = 'Page' self.currentPageId = 0 self.playingTuneIdx = 0 @@ -323,9 +305,17 @@ class MainWindow( gtk.EventBox ): init_data() #above setupGUI() #above - initialize() #above + self.noteLooper = NoteLooper( 0.2, Constants.DEFAULT_TEMPO * 0.2, INIT_INST, INIT_VOL, INIT_MUTE) + CSoundClient.setMasterVolume( self.getVolume() ) + + for pageId in range( GUIConstants.NUMBER_OF_PAGE_BANK_ROWS * GUIConstants.NUMBER_OF_PAGE_BANK_COLUMNS ): + self.pageBankView.addPage( pageId, False ) + + for tid in range(Constants.NUMBER_OF_TRACKS): + self.handleInstrumentChanged( ( tid, self._data['track_inst'][tid] ) ) + self.handleConfigureEvent( None, None ) # needs to come after pages have been added in initialize() self.show_all() #gtk command @@ -358,28 +348,35 @@ class MainWindow( gtk.EventBox ): if widget.get_active(): #play - tracks = range(Constants.NUMBER_OF_TRACKS) - pages = self._data['tune'] - if len(pages) == 0: - pages = [ self.currentPageId ] - print 'handlePlay() pages=',pages - - pageset = set(pages) - trackset = set(tracks) + #TODO: check for track activation, to not take all + trackset = set(range(Constants.NUMBER_OF_TRACKS)) - self.noteLooper.setTick(0) #TODO: get playback head position - self.noteLooper.setRate( round( self.tempoAdjustment.value, 0 ) * 0.2 ) self.noteLooper.clear() #erase all loaded notes - pagedelay = 0 notes = [] - for p in self._data['tune']: - notes.append([(n['onset'] + pagedelay, n) for n in self._data['notebin'] if n['pageID']==p and n['trackID'] in trackset ] ) - pagedelay += self._data['page_beats'][p] + + if self.playSource == 'Tune': + pagedelay = 0 + for p in self.tuneView.getTune(): + notes += [(n['onset'] + pagedelay, n) for n in self._data['notebin'] \ + if n['pageID']==p and n['trackID'] in trackset ] + pagedelay += self._data['page_beats'][p] * Constants.TICKS_PER_BEAT + elif self.playSource == 'Page': + notes = [(n['onset'], n) for n in self._data['notebin'] \ + if n['pageID']== self.currentPageId and n['trackID'] in trackset ] + pagedelay = self._data['page_beats'][self.currentPageId] * Constants.TICKS_PER_BEAT + else: + print 'ERROR: handlePlay() invalid playSource', self.playSource + return + self.noteLooper.insert(notes) self.noteLooper.setDuration( pagedelay ) + self.noteLooper.setTick(0) #TODO: get playback head position + self.noteLooper.setRate( round( self.tempoAdjustment.value, 0 ) * 0.2 ) - buf = self.noteLooper.next( ) - CSoundClient.sendText( buf ) + next = self.noteLooper.next() + print next + for cmd in next: + CSoundClient.sendText( cmd ) self.playbackTimeout = gobject.timeout_add( 50, self.onTimeout ) self.playing = True @@ -392,37 +389,37 @@ class MainWindow( gtk.EventBox ): self.kb_record = self.playButton.get_active() and self.keyboardRecordButton.get_active() and self.keyboardButton.get_active() def onTimeout(self): - buf = self.noteLooper.next() - CSoundClient.sendText( buf ) + next = self.noteLooper.next() + print len(next) + for cmd in next[:8]: #TODO: fix this! + CSoundClient.sendText( cmd ) self.updateFPS() - curtick = self.noteLooper.getCurrentTick(0,True, time.time()) - curIdx = curtick / ( 4 * Constants.TICKS_PER_BEAT) #TODO - if curIdx != self.tuneView.selectedPageIndex: - self.tuneView.selectPage( curIdx ) + if self.playSource == 'Tune': + curtick = self.noteLooper.getCurrentTick(0,True, time.time()) + curIdx = curtick / ( 4 * Constants.TICKS_PER_BEAT) #TODO + if curIdx != self.tuneView.selectedPageIndex: + self.tuneView.selectPage( curIdx ) return True - #little helper function - def dirty_track(self, tid ): - def asdf( note): - if note['trackID'] == tid: - note['dirty'] = True - map( asdf, self._data['notebin'] ) - def onMuteTrack( self, widget, trackID ): - self.dirty_track(trackID) self._data['track_mute'][trackID] = not self._data['track_mute'][trackID] + if self._data['track_mute'][trackID]: + self.noteLooper.setMute( trackID, 0.0 ) + else: + self.noteLooper.setMute( trackID, 1.0 ) def handleTrackVolumeChanged( self, widget, trackID ): - self.dirty_track(trackID) - self._data['track_volume'][trackID] = widget.get_value() + v = widget.get_value() + self._data['track_volume'][trackID] = v + self.noteLooper.setVolume( trackID, v ) # data is tuple ( trackID, instrumentName ) def handleInstrumentChanged( self, data ): (id, instrumentName) = data - self.dirty_track(id) self._data['track_inst'][id] = instrumentName + self.noteLooper.setInstrument(id, instrumentName) recordButton = self.instrumentRecordButtons[ id ] if instrumentName in CSoundConstants.RECORDABLE_INSTRUMENTS: @@ -475,36 +472,23 @@ class MainWindow( gtk.EventBox ): if tracks == []: return set(range(0,Constants.NUMBER_OF_TRACKS)) else: return set(tracks) - def addNotes_fromDict( dict, replace = True ): - - # dict == { trackId : { pageId : notelist } } - noteList = [] - page_notes = self._data['page_notes'] - for tid in dict: - pdict = dict[tid] - for pid in pdict: - if len( pdict[pid] ) > 0 : - if replace: page_notes[pid][tid] = [] - _track = page_notes[pid][tid] - for note in pdict[pid]: - bisect.insort( _track, (note['onset'], note)) - noteList += [ note for (o,note) in _track] #shallow copy! - self._data['notebin'] += noteList - dict = {} for t in range(Constants.NUMBER_OF_TRACKS): dict[t] = {} for p in range(Constants.NUMBER_OF_PAGES): dict[t][p] = [] + newtracks = none_to_all( self.trackInterface.getSelectedTracks()) + newpages = self.pageBankView.getSelectedPageIds() + algo( params, self._data['track_volume'][:], self._data['track_inst'][:], self._data['tempo'], 4, #beats per page TODO: talk to olivier about handling pages of different sizes - none_to_all( self.trackInterface.getSelectedTracks()), - self.pageBankView.getSelectedPageIds(), + newtracks, + newpages, dict) # filter for invalid input @@ -517,15 +501,17 @@ class MainWindow( gtk.EventBox ): note.duration = intdur note.pageID = page note.trackID = track - - newdict = {} + + # TODO: remove notes from the tracks we are replacing + #add notes to self._data + newnotes = [] for tid in dict: - tdict = {} - newdict[tid] = tdict for pid in dict[tid]: - newdict[tid][pid] = map( note_from_CSoundNote, dict[tid][pid]) + newnotes += [note_from_CSoundNote(n) for n in dict[tid][pid]] - addNotes_fromDict(newdict) + self._data['notebin'] = \ + [n for n in self._data['notebin'] if not (n['trackID'] in newtracks and n['pageID'] in newpages) ] \ + + newnotes pageList = [] trackList = [] @@ -600,17 +586,19 @@ class MainWindow( gtk.EventBox ): # callback functions #----------------------------------- def selectPage(self, pageId): - print 'INFO: selecting page', pageId self.trackInterface.displayPage(pageId,int(round( self.beatsPerPageAdjustment.value))) self.currentPageId = pageId + #can be called either by playback switching pages, or mouse switching pages def onTuneViewSelect(self, pageId, tuneIdx): self.pageBankView.selectPage( self.pageBankView.NO_PAGE, False, True ) #de-select the tuneView self.selectPage(pageId) + self.playSource = 'Tune' def onPageBankSelect(self, pageId): self.tuneView.selectPage( self.tuneView.NO_PAGE, False ) #de-select the tuneView self.selectPage(pageId) + self.playSource = 'Page' def onPageBankDrop( self, pageId, pageIdx ): self.tuneView.removePage(pageIdx) |