Print des notes, hauteurs midi et durées.
[minwii.git] / src / controllers / Wiimote.py
1 '''
2 Created on 15 juil. 2009
3
4 @author: Samuel Benveniste
5 '''
6 from gui.constants import *
7
8 class Wiimote:
9 '''
10 Object representing a Wiimote
11
12 number:
13 The number of the Wiimote
14 port:
15 The pypm object representing the MIDI port on which the Wiimote emits
16 instrument:
17 The instrument associated with the Wiimote
18 cursor:
19 The cursor associated with the Wiimote
20 '''
21
22 def __init__(self, number, portNumber, port, instrument, cursor):
23 '''
24 Constructor
25
26 number:
27 The number of the Wiimote
28 portNumber:
29 The number of the port (as numbered by pypm) on which the wiimote emits
30 port:
31 The pypm object representing the MIDI port on which the Wiimote emits
32 instrument:
33 The instrument associated with the Wiimote
34 cursor:
35 The cursor associated with the Wiimote
36 '''
37
38 self.number = number
39 self.portNumber = portNumber
40 self.port = port
41 self.instrument = instrument
42 self.cursor = cursor
43 self.numberPlayed = 0
44
45 def getNoteOnHexCode(self):
46 return (0x90 + self.instrument.channel - 1)
47
48 def getAftertouchHexCode(self):
49 return (0xA0 + self.instrument.channel - 1)
50
51 def getCCHexCode(self):
52 return (0xB0 + self.instrument.channel - 1)
53
54 def playNote(self, note, velocity):
55 noteNumber = self.instrument.getNote(note)
56
57 if noteNumber != None :
58 noteOnHexCode = self.getNoteOnHexCode()
59 CCHexCode = self.getCCHexCode()
60 else :
61 noteNumber = defaultInstrumentNote
62 noteOnHexCode = defaultNoteOnHexCode
63 CCHexCode = defaultCCHexCode
64
65 self.port.write_short(noteOnHexCode, noteNumber , 127)
66 self.port.write_short(CCHexCode, 07, velocity)
67
68 def playNoteByNoteNumber(self, midiNoteNumber, velocity):
69 noteNumber = self.instrument.getNoteByNoteNumber(midiNoteNumber)
70
71 if noteNumber != None :
72 noteOnHexCode = self.getNoteOnHexCode()
73 CCHexCode = self.getCCHexCode()
74 else :
75 noteNumber = defaultInstrumentNote
76 noteOnHexCode = defaultNoteOnHexCode
77 CCHexCode = defaultCCHexCode
78
79 self.port.write_short(noteOnHexCode, noteNumber , 127)
80 self.port.write_short(CCHexCode, 07, velocity)
81
82 self.numberPlayed += 1
83
84 def stopNote(self, note):
85 noteNumber = self.instrument.getNote(note)
86 if noteNumber != None :
87 noteOnHexCode = self.getNoteOnHexCode()
88 else :
89 noteNumber = defaultInstrumentNote
90 noteOnHexCode = defaultNoteOnHexCode
91
92 self.port.write_short(noteOnHexCode, noteNumber, 0)
93
94 def stopNoteByNoteNumber(self, midiNoteNumber):
95 noteNumber = self.instrument.getNoteByNoteNumber(midiNoteNumber)
96 if noteNumber != None :
97 noteOnHexCode = self.getNoteOnHexCode()
98 else :
99 noteNumber = defaultInstrumentNote
100 noteOnHexCode = defaultNoteOnHexCode
101
102 self.port.write_short(noteOnHexCode, noteNumber, 0)
103
104 def allNotesOff(self):
105 CCHexCode = self.getCCHexCode()
106 self.port.write_short(CCHexCode,123,0)