diff options
author | Nathanaël Lécaudé <Nat@localhost.localdomain> | 2006-11-17 03:27:11 (GMT) |
---|---|---|
committer | Nathanaël Lécaudé <Nat@localhost.localdomain> | 2006-11-17 03:27:11 (GMT) |
commit | ed7581b13b44abe41ea7bd70cee5d0bcd08921fe (patch) | |
tree | a5befbcdaa36eaf9f9d8bffbfb4616c793013a3b | |
parent | b43c1f537ce56f75995e80de1d72eaf06445e000 (diff) | |
parent | 04150616325831fa10acbb79cff9ff2baabd13eb (diff) |
Merge branch 'master' of git+ssh://natcl@dev.laptop.org/git/projects/tamtam
-rw-r--r-- | Framework/Music.py | 35 | ||||
-rw-r--r-- | Framework/Note.py | 5 | ||||
-rw-r--r-- | GUI/Core/MainWindow.py | 6 |
3 files changed, 36 insertions, 10 deletions
diff --git a/Framework/Music.py b/Framework/Music.py index c46fe7d..1f57fbf 100644 --- a/Framework/Music.py +++ b/Framework/Music.py @@ -8,6 +8,7 @@ from Framework.Generation.Generator import GenerationParameters _notebin = [] _data = {} +_listeners = [] def music_init(): @@ -38,17 +39,21 @@ def music_init(): _data['tune'] = [] +def music_addListener( fn ): + _listeners.append(fn) + def music_addPage( pid, nbeats): _data['page_notes'][pid] = map(lambda i : [], range(Constants.NUMBER_OF_TRACKS)) _data['page_beats'][pid] = nbeats _data['page_ticks'][pid] = nbeats * Constants.TICKS_PER_BEAT -def music_addNotes_fromDict( dict, replace = False ): + +def music_addNotes_fromDict( dict, replace = True ): global _notebin - # { trackId : { pageId : notelist } } + # dict == { trackId : { pageId : notelist } } + noteList = [] page_notes = _data['page_notes'] - page_ticks = _data['page_ticks'] for tid in dict: pdict = dict[tid] for pid in pdict: @@ -57,13 +62,27 @@ def music_addNotes_fromDict( dict, replace = False ): _track = page_notes[pid][tid] for note in pdict[pid]: bisect.insort( _track, (note['onset'], note)) - _notebin += map( lambda (o,note): note, _track ) #shallow copy! + noteList += map( lambda (o,note): note, _track ) #shallow copy! + _notebin += noteList + + map( lambda x: x('add', noteList), _listeners) -def music_setNotes(): - raise 'not Implemented' +def music_addNotes( noteList ): + global _notebin + for note in noteList: + bisect.insort( _data['page_notes'][note['pageID']][note['trackID']], (note['onset'], note)) + _notebin.append(note) + map( lambda x: x('add', noteList), _listeners) + +def music_setNotes( noteList ): + map( lambda x: x('set', noteList), _listeners) -def music_delNotes(): - raise 'not Implemented' +def music_delNotes( noteList ): + global _notebin + for note in noteList: + _notebin.remove(note) + _data['page_notes'][note['pageID']][note['trackID']].remove( (note['onset'], note)) + map( lambda x: x('del', noteList), _listeners) def music_getNotes( pages, tracks ): # unify given pages and tracks into a single note list diff --git a/Framework/Note.py b/Framework/Note.py index bb0d877..a6168de 100644 --- a/Framework/Note.py +++ b/Framework/Note.py @@ -9,6 +9,7 @@ def note_new( pan, duration, trackID, + pageID, fullDuration = False, instrument = CSoundConstants.FLUTE, attack = 0.002, @@ -27,7 +28,7 @@ def note_new( note['pan'] = pan note['duration'] = duration note['trackID'] = trackID - #note['instrument'] = instrument + note['pageID'] = pageID note['fullDuration'] = fullDuration note['attack'] = attack note['decay'] = decay @@ -53,7 +54,7 @@ def note_from_CSoundNote( csnote ): note['pan'] = csnote.pan note['duration'] = csnote.duration note['trackID'] = csnote.trackID - #note['instrument'] = csnote.instrument + note['pageID'] = csnote.pageID note['fullDuration'] = csnote.fullDuration note['attack'] = csnote.attack note['decay'] = csnote.decay diff --git a/GUI/Core/MainWindow.py b/GUI/Core/MainWindow.py index 314b568..27e6fb6 100644 --- a/GUI/Core/MainWindow.py +++ b/GUI/Core/MainWindow.py @@ -264,6 +264,7 @@ class MainWindow( gtk.EventBox ): self.fpsLastTime = time.time() # fps will be borked for the first few frames but who cares? music_init() + music_addListener(self.onScoreChange) setupGUI() #above initialize() #above @@ -390,6 +391,9 @@ class MainWindow( gtk.EventBox ): self.kb_record = self.playButton.get_active() and self.keyboardRecordButton.get_active() + def onScoreChange( self, action, noteList ): + pass + #----------------------------------- # generation functions @@ -434,6 +438,8 @@ class MainWindow( gtk.EventBox ): if intdur != note.duration: print "Invalid note duration!" note.duration = intdur + note.pageID = page + note.trackID = track newdict = {} for tid in dict: |