e75cdc3b631fd40b1514ca7b7288e4f4c6ed3834
2 Created on 15 juil. 2009
4 @author: Samuel Benveniste
6 from gui
.constants
import *
11 Object representing a Wiimote
14 The number of the Wiimote
16 The pypm object representing the MIDI port on which the Wiimote emits
18 The instrument associated with the Wiimote
20 The cursor associated with the Wiimote
23 def __init__(self
, number
, portNumber
, port
, instrument
, cursor
):
28 The number of the Wiimote
30 The number of the port (as numbered by pypm) on which the wiimote emits
32 The pypm object representing the MIDI port on which the Wiimote emits
34 The instrument associated with the Wiimote
36 The cursor associated with the Wiimote
39 self
.portNumber
= portNumber
41 self
.instrument
= instrument
45 self
.fs
= fs
= fluidsynth
.Synth()
47 soundFont
= r
"C:\Documents and Settings\Administrator\My Documents\Telechargements\fluid-soundfont-3.1\FluidR3_GM.sf2"
48 self
.fsid
= fsid
= fs
.sfload(soundFont
)
51 fs
.program_select(0, fsid
, bank
, preset
)
56 def getNoteOnHexCode(self
):
57 return (0x90 + self
.instrument
.channel
- 1)
59 def getAftertouchHexCode(self
):
60 return (0xA0 + self
.instrument
.channel
- 1)
62 def getCCHexCode(self
):
63 return (0xB0 + self
.instrument
.channel
- 1)
65 # def playNote(self, note, velocity):
67 # noteNumber = self.instrument.getNote(note)
69 # if noteNumber != None :
70 # noteOnHexCode = self.getNoteOnHexCode()
71 # CCHexCode = self.getCCHexCode()
73 # noteNumber = defaultInstrumentNote
74 # noteOnHexCode = defaultNoteOnHexCode
75 # CCHexCode = defaultCCHexCode
77 # self.port.write_short(noteOnHexCode, noteNumber , 127)
78 # self.port.write_short(CCHexCode, 07, velocity)
80 def playNoteByNoteNumber(self
, midiNoteNumber
, velocity
):
81 print 'playNoteByNumber'
82 noteNumber
= self
.instrument
.getNoteByNoteNumber(midiNoteNumber
)
84 fs
.noteon(0, noteNumber
, velocity
)
87 noteNumber
= self
.instrument
.getNoteByNoteNumber(midiNoteNumber
)
89 if noteNumber
!= None :
90 noteOnHexCode
= self
.getNoteOnHexCode()
91 CCHexCode
= self
.getCCHexCode()
93 noteNumber
= defaultInstrumentNote
94 noteOnHexCode
= defaultNoteOnHexCode
95 CCHexCode
= defaultCCHexCode
97 self
.port
.write_short(noteOnHexCode
, noteNumber
, 127)
98 self
.port
.write_short(CCHexCode
, 07, velocity
)
100 self
.numberPlayed
+= 1
102 # def stopNote(self, note):
104 # noteNumber = self.instrument.getNote(note)
105 # if noteNumber != None :
106 # noteOnHexCode = self.getNoteOnHexCode()
108 # noteNumber = defaultInstrumentNote
109 # noteOnHexCode = defaultNoteOnHexCode
111 # self.port.write_short(noteOnHexCode, noteNumber, 0)
113 def stopNoteByNoteNumber(self
, midiNoteNumber
):
114 print 'stopNoteByNoteNumber'
116 noteNumber
= self
.instrument
.getNoteByNoteNumber(midiNoteNumber
)
118 fs
.noteoff(0, noteNumber
)
121 noteNumber
= self
.instrument
.getNoteByNoteNumber(midiNoteNumber
)
122 if noteNumber
!= None :
123 noteOnHexCode
= self
.getNoteOnHexCode()
125 noteNumber
= defaultInstrumentNote
126 noteOnHexCode
= defaultNoteOnHexCode
128 self
.port
.write_short(noteOnHexCode
, noteNumber
, 0)
130 # def allNotesOff(self):
132 # CCHexCode = self.getCCHexCode()
133 # self.port.write_short(CCHexCode,123,0)