X-Git-Url: https://scm.cri.ensmp.fr/git/minwii.git/blobdiff_plain/928c4fcf26174df9b8cf62d67e0061ad703481e9..c1cf9353fbc403b2b446ba315e7bc84c4ac71ded:/src/controllers/Wiimote.py?ds=inline diff --git a/src/controllers/Wiimote.py b/src/controllers/Wiimote.py index 7536881..e75cdc3 100755 --- a/src/controllers/Wiimote.py +++ b/src/controllers/Wiimote.py @@ -4,6 +4,7 @@ Created on 15 juil. 2009 @author: Samuel Benveniste ''' from gui.constants import * +import fluidsynth class Wiimote: ''' @@ -34,7 +35,6 @@ class Wiimote: cursor: The cursor associated with the Wiimote ''' - self.number = number self.portNumber = portNumber self.port = port @@ -42,6 +42,17 @@ class Wiimote: self.cursor = cursor self.numberPlayed = 0 + self.fs = fs = fluidsynth.Synth() + fs.start() + soundFont = r"C:\Documents and Settings\Administrator\My Documents\Telechargements\fluid-soundfont-3.1\FluidR3_GM.sf2" + self.fsid = fsid = fs.sfload(soundFont) + bank = 0 + preset = 0 + fs.program_select(0, fsid, bank, preset) + + def __del__(self) : + self.fs.delete() + def getNoteOnHexCode(self): return (0x90 + self.instrument.channel - 1) @@ -51,21 +62,28 @@ class Wiimote: def getCCHexCode(self): return (0xB0 + self.instrument.channel - 1) - def playNote(self, note, velocity): - noteNumber = self.instrument.getNote(note) - - if noteNumber != None : - noteOnHexCode = self.getNoteOnHexCode() - CCHexCode = self.getCCHexCode() - else : - noteNumber = defaultInstrumentNote - noteOnHexCode = defaultNoteOnHexCode - CCHexCode = defaultCCHexCode - - self.port.write_short(noteOnHexCode, noteNumber , 127) - self.port.write_short(CCHexCode, 07, velocity) +# def playNote(self, note, velocity): +# print 'playNote' +# noteNumber = self.instrument.getNote(note) +# +# if noteNumber != None : +# noteOnHexCode = self.getNoteOnHexCode() +# CCHexCode = self.getCCHexCode() +# else : +# noteNumber = defaultInstrumentNote +# noteOnHexCode = defaultNoteOnHexCode +# CCHexCode = defaultCCHexCode +# +# self.port.write_short(noteOnHexCode, noteNumber , 127) +# self.port.write_short(CCHexCode, 07, velocity) def playNoteByNoteNumber(self, midiNoteNumber, velocity): + print 'playNoteByNumber' + noteNumber = self.instrument.getNoteByNoteNumber(midiNoteNumber) + fs = self.fs + fs.noteon(0, noteNumber, velocity) + + return noteNumber = self.instrument.getNoteByNoteNumber(midiNoteNumber) if noteNumber != None : @@ -81,17 +99,25 @@ class Wiimote: self.numberPlayed += 1 - def stopNote(self, note): - noteNumber = self.instrument.getNote(note) - if noteNumber != None : - noteOnHexCode = self.getNoteOnHexCode() - else : - noteNumber = defaultInstrumentNote - noteOnHexCode = defaultNoteOnHexCode - - self.port.write_short(noteOnHexCode, noteNumber, 0) +# def stopNote(self, note): +# print 'stopNote' +# noteNumber = self.instrument.getNote(note) +# if noteNumber != None : +# noteOnHexCode = self.getNoteOnHexCode() +# else : +# noteNumber = defaultInstrumentNote +# noteOnHexCode = defaultNoteOnHexCode +# +# self.port.write_short(noteOnHexCode, noteNumber, 0) def stopNoteByNoteNumber(self, midiNoteNumber): + print 'stopNoteByNoteNumber' + + noteNumber = self.instrument.getNoteByNoteNumber(midiNoteNumber) + fs = self.fs + fs.noteoff(0, noteNumber) + + return noteNumber = self.instrument.getNoteByNoteNumber(midiNoteNumber) if noteNumber != None : noteOnHexCode = self.getNoteOnHexCode() @@ -101,6 +127,7 @@ class Wiimote: self.port.write_short(noteOnHexCode, noteNumber, 0) - def allNotesOff(self): - CCHexCode = self.getCCHexCode() - self.port.write_short(CCHexCode,123,0) \ No newline at end of file +# def allNotesOff(self): +# print 'allNoteOff' +# CCHexCode = self.getCCHexCode() +# self.port.write_short(CCHexCode,123,0)