-
Notifications
You must be signed in to change notification settings - Fork 67
/
MIDIPlugin.class.st
147 lines (121 loc) · 4.13 KB
/
MIDIPlugin.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"
Provide MIDI support, if your platform provides it.
"
Class {
#name : #MIDIPlugin,
#superclass : #SmartSyntaxInterpreterPlugin,
#category : #'VMMaker-Plugins'
}
{ #category : #translation }
MIDIPlugin class >> hasHeaderFile [
"If there is a single intrinsic header file to be associated with the plugin, here is where you want to flag"
^true
]
{ #category : #translation }
MIDIPlugin class >> requiresPlatformFiles [
"this plugin requires platform specific files in order to work"
^true
]
{ #category : #'initialize-release' }
MIDIPlugin >> initialiseModule [
<export: true>
^self cCode: 'midiInit()' inSmalltalk:[true]
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIClosePort: portNum [
self primitive: 'primitiveMIDIClosePort'
parameters: #(SmallInteger).
self sqMIDIClosePort: portNum
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIGetClock [
"Return the value of the MIDI clock as a SmallInteger. The range is limited to SmallInteger maxVal / 2 to allow scheduling MIDI events into the future without overflowing a SmallInteger. The sqMIDIGetClock function is assumed to wrap at or before 16r20000000."
| clockValue |
self primitive: 'primitiveMIDIGetClock'.
clockValue := self sqMIDIGetClock bitAnd: 16r1FFFFFFF.
^clockValue asSmallIntegerObj
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIGetPortCount [
| n |
self primitive: 'primitiveMIDIGetPortCount'.
n := self sqMIDIGetPortCount.
^n asSmallIntegerObj
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIGetPortDirectionality: portNum [
| dir |
self primitive: 'primitiveMIDIGetPortDirectionality'
parameters: #(SmallInteger).
dir := self sqMIDIGetPortDirectionality: portNum.
^dir asSmallIntegerObj
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIGetPortName: portNum [
| portName sz nameObj |
<var: #portName declareC: 'char portName[256]'>
self primitive: 'primitiveMIDIGetPortName' parameters: #(SmallInteger).
sz := self sqMIDIGet: portNum Port: portName Name: 255.
nameObj := interpreterProxy instantiateClass: interpreterProxy classString indexableSize: sz.
interpreterProxy failed ifTrue: [^nil].
self memcpy: (nameObj asValue: String) _: portName _: sz.
^nameObj
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIOpenPort: portNum sema: semaIndex speed: clockRate [
self primitive: 'primitiveMIDIOpenPort'
parameters: #(SmallInteger SmallInteger SmallInteger).
self cCode: 'sqMIDIOpenPort(portNum, semaIndex, clockRate)'
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIParameterGet: whichParameter [
| currentValue |
"read parameter"
self primitive: 'primitiveMIDIParameterGet'
parameters: #(SmallInteger).
currentValue := self cCode: 'sqMIDIParameterGet(whichParameter)'.
^currentValue asSmallIntegerObj
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIParameterGetOrSet [
"Backward compatibility"
<export: true>
interpreterProxy methodArgumentCount = 1
ifTrue:[^self primitiveMIDIParameterGet]
ifFalse:[^self primitiveMIDIParameterSet]
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIParameterSet: whichParameter value: newValue [
"write parameter"
self primitive:'primitiveMIDIParameterSet'
parameters:#(SmallInteger SmallInteger).
self cCode: 'sqMIDIParameterSet(whichParameter, newValue)'
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIRead: portNum into: array [
| arrayLength bytesRead |
self primitive: 'primitiveMIDIRead'
parameters: #(SmallInteger ByteArray).
arrayLength := interpreterProxy byteSizeOf: array cPtrAsOop.
bytesRead := self sqMIDIPort: portNum
Read: arrayLength
Into: array.
^bytesRead asSmallIntegerObj
]
{ #category : #primitives }
MIDIPlugin >> primitiveMIDIWrite: portNum from: array at: time [
| arrayLength bytesWritten |
self primitive: 'primitiveMIDIWrite'
parameters: #(SmallInteger ByteArray SmallInteger).
arrayLength := interpreterProxy byteSizeOf: array cPtrAsOop.
bytesWritten := self sqMIDIPort: portNum
Write: arrayLength
From: array
At: time.
^bytesWritten asSmallIntegerObj
]
{ #category : #'initialize-release' }
MIDIPlugin >> shutdownModule [
<export: true>
^self cCode: 'midiShutdown()' inSmalltalk:[true]
]