7536881699b9cb0788ce588b26bfa94dab783f1d
2 Created on 15 juil. 2009
4 @author: Samuel Benveniste
6 from gui
.constants
import *
10 Object representing a Wiimote
13 The number of the Wiimote
15 The pypm object representing the MIDI port on which the Wiimote emits
17 The instrument associated with the Wiimote
19 The cursor associated with the Wiimote
22 def __init__(self
, number
, portNumber
, port
, instrument
, cursor
):
27 The number of the Wiimote
29 The number of the port (as numbered by pypm) on which the wiimote emits
31 The pypm object representing the MIDI port on which the Wiimote emits
33 The instrument associated with the Wiimote
35 The cursor associated with the Wiimote
39 self
.portNumber
= portNumber
41 self
.instrument
= instrument
45 def getNoteOnHexCode(self
):
46 return (0x90 + self
.instrument
.channel
- 1)
48 def getAftertouchHexCode(self
):
49 return (0xA0 + self
.instrument
.channel
- 1)
51 def getCCHexCode(self
):
52 return (0xB0 + self
.instrument
.channel
- 1)
54 def playNote(self
, note
, velocity
):
55 noteNumber
= self
.instrument
.getNote(note
)
57 if noteNumber
!= None :
58 noteOnHexCode
= self
.getNoteOnHexCode()
59 CCHexCode
= self
.getCCHexCode()
61 noteNumber
= defaultInstrumentNote
62 noteOnHexCode
= defaultNoteOnHexCode
63 CCHexCode
= defaultCCHexCode
65 self
.port
.write_short(noteOnHexCode
, noteNumber
, 127)
66 self
.port
.write_short(CCHexCode
, 07, velocity
)
68 def playNoteByNoteNumber(self
, midiNoteNumber
, velocity
):
69 noteNumber
= self
.instrument
.getNoteByNoteNumber(midiNoteNumber
)
71 if noteNumber
!= None :
72 noteOnHexCode
= self
.getNoteOnHexCode()
73 CCHexCode
= self
.getCCHexCode()
75 noteNumber
= defaultInstrumentNote
76 noteOnHexCode
= defaultNoteOnHexCode
77 CCHexCode
= defaultCCHexCode
79 self
.port
.write_short(noteOnHexCode
, noteNumber
, 127)
80 self
.port
.write_short(CCHexCode
, 07, velocity
)
82 self
.numberPlayed
+= 1
84 def stopNote(self
, note
):
85 noteNumber
= self
.instrument
.getNote(note
)
86 if noteNumber
!= None :
87 noteOnHexCode
= self
.getNoteOnHexCode()
89 noteNumber
= defaultInstrumentNote
90 noteOnHexCode
= defaultNoteOnHexCode
92 self
.port
.write_short(noteOnHexCode
, noteNumber
, 0)
94 def stopNoteByNoteNumber(self
, midiNoteNumber
):
95 noteNumber
= self
.instrument
.getNoteByNoteNumber(midiNoteNumber
)
96 if noteNumber
!= None :
97 noteOnHexCode
= self
.getNoteOnHexCode()
99 noteNumber
= defaultInstrumentNote
100 noteOnHexCode
= defaultNoteOnHexCode
102 self
.port
.write_short(noteOnHexCode
, noteNumber
, 0)
104 def allNotesOff(self
):
105 CCHexCode
= self
.getCCHexCode()
106 self
.port
.write_short(CCHexCode
,123,0)