Subversion Repositories svn.mios

Rev

Rev 881 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
44 tk 1
; $Id: sid_midi_d.inc 1122 2013-04-20 12:37:28Z tk $
1 tk 2
;
3
; MIDIbox SID
4
; MIDI Interface part for Drum Engine
5
;
6
; ==========================================================================
7
;
8
;  Copyright 1998-2007 Thorsten Klose (tk@midibox.org)
9
;  Licensed for personal non-commercial use only.
10
;  All other rights reserved.
11
;
12
; ==========================================================================
13
 
14
 
15
;; --------------------------------------------------------------------------
16
;;  This function is called to forward a Note On event to the synthesizer
17
;;  Input:
18
;;     o MIDI Voice in SID_CURRENT_MIDI_VOICE
19
;;     o MIDI channel in SID_CURRENT_CHANNEL
20
;;     o note number in SID_MIDI_PARAMETER1
21
;;     o velocity in SID_MIDI_PARAMETER2
22
;; --------------------------------------------------------------------------
23
SID_MIDI_D_NoteOn
24
 
25
	;; drum engine works only with settings of first MIDI voice
26
	;; note that SID_CURRENT_MIDIVOICE has a different meaning here.
27
	;; It doesn't select the MVx record, but identifies the drum instrument
28
	lfsr	FSR0, SID_MV1_BASE
29
 
30
	;; check if MIDI channel and split zone matches
31
	call	SID_MIDI_Hlp_ChkChnAndSplit
32
	bnz	SID_MIDI_D_NoteOn_End
33
 
34
	;; push note into stack
35
	lfsr	FSR2, SID_MV1_BASE + SID_MVx_NOTE_STACK_0
36
	call	SID_MIDI_Hlp_PushNote
37
 
38
	;; normalize note (1..24) -> SID_CURRENT_MIDIVOICE
39
	movf	SID_MIDI_PARAMETER1, W
40
	rcall	SID_MIDI_D_Hlp_GetNote
41
	movwf	SID_CURRENT_MIDIVOICE, BANKED
42
 
43
	;; branch depending on SEQ/Normal mode
44
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_D_SEQ_SPEED, WREG
45
	andlw	(1 << SID_I_V_SEQ_ON)
46
	bnz	SID_MIDI_D_NoteOn_Seq
47
SID_MIDI_D_NoteOn_Norm
48
	;; ignore notes >= 17
49
	movlw	17
50
	cpfslt	SID_CURRENT_MIDIVOICE, BANKED
51
	rgoto SID_MIDI_D_NoteOn_End
52
 
53
	;; forward velocity to Knob handler
54
	clrc
55
	rlf	SID_MIDI_PARAMETER2, W, BANKED
56
	movwf	MIOS_PARAMETER1
57
	movlw	SID_KNOB_VEL
58
	call	SID_KNOB_SetValue
59
 
60
	;; dedicated velocity assignment for instrument
61
	movff	SID_MIDI_PARAMETER2, MIOS_PARAMETER2	; high byte
62
	clrc
63
	rlf	MIOS_PARAMETER2, F
64
	clrf	MIOS_PARAMETER1				; low byte
65
	decf	SID_CURRENT_MIDIVOICE, W, BANKED	; current instrument
66
	swapf	WREG, W
67
	andlw	0xf0
68
	iorlw	0x03
69
	movwf	MIOS_PARAMETER3
70
	call	SID_SE_D_Hlp_FSR2_Ins			; pointer to instrument -> FSR2
71
	movlw	SID_Ix_Dx_VELOCITY_ASSGN		; velocity assignment
72
	movf	PLUSW2, W
73
	call	SID_PARIN_Set16
74
 
75
	;; call note-on handler
76
	movff	SID_MIDI_PARAMETER2, MIOS_PARAMETER2	; expects velcoity in MIOS_PARAMETER2 to control accent flag
77
	call	SID_SE_D_NoteOn		; also used by sound engine, therefore located there
78
	rgoto	SID_MIDI_D_NoteOn_End
79
 
80
SID_MIDI_D_NoteOn_Seq
81
	;; forward velocity to Knob handler
82
	clrc
83
	rlf	SID_MIDI_PARAMETER2, W, BANKED
84
	movwf	MIOS_PARAMETER1
85
	movlw	SID_KNOB_VEL
86
	call	SID_KNOB_SetValue
87
 
88
	;; reset sequencer if voice was not active before
89
 
90
	;; only used in master mode
91
	BRA_IFSET SID_STAT, SID_STAT_CLK_SLAVE, ACCESS, SID_MIDI_D_NoteOn_Seq_NoR
92
 
93
	movff	SID_SEQ1_BASE + SID_SEQx_MISC, WREG
94
	BRA_IFSET WREG, SID_SEQ_MISC_SEQ_RUNNING, ACCESS, SID_MIDI_D_NoteOn_Seq_NoR
95
SID_MIDI_D_NoteOn_Seq_R
96
	movlw	0x40
97
	iorwf	SID_SE_TRG_EVNT_U, F, BANKED
98
SID_MIDI_D_NoteOn_Seq_NoR
99
 
100
	;; select new sequence, ensure that sequence number is within one octave
101
	;; (it's already between two octaves)
102
	decf	SID_CURRENT_MIDIVOICE, W, BANKED
103
	movwf	PRODL
104
	movlw	12-1
105
	cpfsgt	PRODL, ACCESS
106
	rgoto SID_MIDI_D_NoteOn_Seq_OctOk
107
SID_MIDI_D_NoteOn_Seq_OctFix
108
	movlw	-12
109
	addwf	PRODL, F
110
SID_MIDI_D_NoteOn_Seq_OctOk
111
	movf	PRODL, W
112
	rcall	SID_MIDI_D_Hlp_SetSeq
113
 
114
	;; enable sequencer
115
	SET_BSR	SID_SEQ1_BASE
116
	bsf	SID_SEQ1_BASE + SID_SEQx_MISC, SID_SEQ_MISC_SEQ_RUNNING, BANKED
117
	SET_BSR	SID_BASE
118
 
119
	;; 	rgoto	SID_MIDI_D_NoteOn_End
120
 
121
SID_MIDI_D_NoteOn_End
122
	return
123
 
124
 
125
;; --------------------------------------------------------------------------
126
;;  This function is called to forward a Note Off event to the synthesizer
127
;;  Input:
128
;;     o MIDI channel in SID_CURRENT_CHANNEL
129
;;     o note number in SID_MIDI_PARAMETER1
130
;;     o velocity in SID_MIDI_PARAMETER2
131
;; --------------------------------------------------------------------------
132
SID_MIDI_D_NoteOff
133
	SET_BSR	SID_BASE
134
 
135
	;; drum engine works only with settings of first MIDI voice
136
	;; note that SID_CURRENT_MIDIVOICE has a different meaning here.
137
	;; It doesn't select the MVx record, but identifies the drum instrument
138
	lfsr	FSR0, SID_MV1_BASE
139
 
140
	;; check if MIDI channel and split zone matches
141
	call	SID_MIDI_Hlp_ChkChnAndSplit
142
	bnz	SID_MIDI_D_NoteOff_End
143
 
144
	;; branch depending on SEQ/Normal mode
145
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_D_SEQ_SPEED, WREG
146
	andlw	(1 << SID_I_V_SEQ_ON)
147
	bnz	SID_MIDI_D_NoteOff_Seq
148
 
149
SID_MIDI_D_NoteOff_Norm
881 tk 150
	;; pop note from stack
151
	lfsr	FSR2, SID_MV1_BASE + SID_MVx_NOTE_STACK_0
152
	call	SID_MIDI_Hlp_PopNote
153
	;; 	bnz	SID_MIDI_D_NoteOff_End ; ZERO flag cleared: note not found!
154
	;; not here! we are able to play more drums than note stack depth!
155
 
1 tk 156
	;; normalize note (1..24) -> SID_CURRENT_MIDIVOICE
157
	movf	SID_MIDI_PARAMETER1, W
158
	rcall	SID_MIDI_D_Hlp_GetNote
159
	movwf	SID_CURRENT_MIDIVOICE, BANKED
160
 
161
	;; ignore notes >= 17
162
	movlw	17
163
	cpfslt	SID_CURRENT_MIDIVOICE, BANKED
164
	rgoto SID_MIDI_D_NoteOff_End
165
 
166
	;; call note-off handler
167
	call	SID_SE_D_NoteOff		; also used by sound engine, therefore located there
168
	rgoto	SID_MIDI_D_NoteOff_End
169
 
170
SID_MIDI_D_NoteOff_Seq
171
 
881 tk 172
	;; pop note from stack
173
	lfsr	FSR2, SID_MV1_BASE + SID_MVx_NOTE_STACK_0
174
	call	SID_MIDI_Hlp_PopNote
175
	bnz	SID_MIDI_D_NoteOff_End ; ZERO flag cleared: note not found!
176
 
1 tk 177
	;; select sequence if there is still a note in stack
178
	movlw	SID_MVx_NOTE_STACK_PTR
179
	movf	PLUSW0, W
180
	bz	SID_MIDI_D_NoteOff_Seq_NoNew
181
SID_MIDI_D_NoteOff_Seq_New
182
	rcall	SID_MIDI_D_Hlp_GetNote
183
	addlw	-1
184
	rcall	SID_MIDI_D_Hlp_SetSeq
185
SID_MIDI_D_NoteOff_Seq_NoNew
186
 
187
	;; disable sequencer if invalid sequence is selected (seq off)
188
 
189
	;; only used in master mode
190
	BRA_IFSET SID_STAT, SID_STAT_CLK_SLAVE, ACCESS, SID_MIDI_D_NoteOff_Loop_Seq_NoDs
191
 
192
	movff	SID_PATCH_BUFFER_SHADOW + SID_Ix_D_SEQ_NUM, WREG
193
	andlw	0xf8
194
	bz	SID_MIDI_D_NoteOff_Loop_Seq_NoDs
195
SID_MIDI_D_NoteOff_Loop_Seq_Dis
196
	SET_BSR	SID_SEQ1_BASE
197
	bcf	SID_SEQ1_BASE + SID_SEQx_MISC, SID_SEQ_MISC_SEQ_RUNNING, BANKED
198
	SET_BSR	SID_BASE
199
SID_MIDI_D_NoteOff_Loop_Seq_NoDs
200
 
201
	;; 	rgoto	SID_MIDI_D_NoteOff_End
202
 
203
SID_MIDI_D_NoteOff_End
204
	return
205
 
206
 
207
;; --------------------------------------------------------------------------
208
;;  This function is called to forward a PitchBender event to the synthesizer
209
;;  Input:
210
;;     o MIDI channel in SID_CURRENT_CHANNEL
211
;;     o 8bit PitchBender value in SID_MIDI_PARAMETER1
212
;; --------------------------------------------------------------------------
213
SID_MIDI_D_PitchBender
214
	SET_BSR	SID_BASE
215
	return
216
 
217
 
218
;; --------------------------------------------------------------------------
219
;;  This function is called to forward a CC event to the synthesizer
220
;;  Input:
221
;;     o MIDI channel in SID_CURRENT_CHANNEL
222
;;     o CC number in SID_MIDI_PARAMETER1
223
;;     o CC value in SID_MIDI_PARAMETER2
224
;; --------------------------------------------------------------------------
225
SID_MIDI_D_CC
226
	SET_BSR	SID_BASE
227
 
228
	;; exit if MIDI channel doesn't match (only check for first MIDI voice)
229
	movff	SID_MV1_BASE + SID_MVx_MIDI_CHANNEL, WREG
230
	cpfseq	SID_CURRENT_CHANNEL, BANKED
231
	rgoto SID_MIDI_D_End
232
 
1122 tk 233
	;; if CC#06 (NRPN data MSB) received, forward to parameter handler
1 tk 234
	movlw	0x06
235
	cpfseq	SID_MIDI_PARAMETER1, BANKED
236
	rgoto SID_MIDI_D_CC_NoNRPNDataH
237
SID_MIDI_D_CC_NRPNDataH
238
	;; prepare MIOS_PARAMETER3 (selection options)
239
	clrf	MIOS_PARAMETER3		; (L/R selection done in NRPN function)
240
	;; (current instrument in MIOS_PARAMETER3[7:4] always 0 - thats ok, as all parameters are accessible with alternative number
241
	call	SID_PARIN_SetNRPN
242
	rgoto	SID_MIDI_D_End
243
SID_MIDI_D_CC_NoNRPNDataH
244
 
1122 tk 245
	;; handle remaining CCs
246
	clrf	MIOS_PARAMETER3
247
	call	SID_CC_TABLE_Set
248
 
1 tk 249
SID_MIDI_D_End
250
	return
251
 
252
 
253
;; --------------------------------------------------------------------------
254
;;  help routines for Drum Engine
255
;; --------------------------------------------------------------------------
256
 
257
 
258
;; --------------------------------------------------------------------------
259
;; Help function which returns the normalized note (1..24)
260
;; IN: MIDI Note in WREG
261
;; --------------------------------------------------------------------------
262
SID_MIDI_D_Hlp_GetNote
263
	;; store MIDI note in PRODL
264
	movwf	PRODL
265
 
266
	;; add MIDI voice based transpose value (ensure that within range 0x00..0x7f)
267
	movlw	SID_MVx_TRANSPOSE
268
	movf	PLUSW0, W
269
	addlw	-0x40
270
	BRA_IFSET WREG, 7, ACCESS, SID_MIDI_D_Hlp_GetNote_TrnN
271
SID_MIDI_D_Hlp_GetNote_TrnP
272
	addwf	PRODL, F
273
	BRA_IFCLR PRODL, 7, ACCESS, SID_MIDI_D_Hlp_GetNote_Trn_Cont
274
	addlw	-12
275
	rgoto	SID_MIDI_D_Hlp_GetNote_TrnP
276
SID_MIDI_D_Hlp_GetNote_TrnN
277
	addwf	PRODL, F
278
	BRA_IFCLR PRODL, 7, ACCESS, SID_MIDI_D_Hlp_GetNote_Trn_Cont
279
	movlw	12
280
	rgoto	SID_MIDI_D_Hlp_GetNote_TrnN
281
SID_MIDI_D_Hlp_GetNote_Trn_Cont
282
 
283
	;; determine instrument based on note number
284
	;; remove 2*octave from note
285
SID_MIDI_D_Hlp_GetNote_RemoveOct
286
	movlw	24 - 1
287
	cpfsgt	PRODL, ACCESS
288
	rgoto SID_MIDI_D_Hlp_GetNote_OctOk
289
	movlw	-24
290
	addwf	PRODL, F
291
	rgoto	SID_MIDI_D_Hlp_GetNote_RemoveOct
292
 
293
SID_MIDI_D_Hlp_GetNote_OctOk
294
 
295
	;; return drum note number
296
	incf	PRODL, W
297
	return
298
 
299
 
300
;; --------------------------------------------------------------------------
301
;; Help function which selects the sequence based on played note
302
;; IN: normalized note in WREG, voice base in FSR1, midi voice base in FSR0
303
;; --------------------------------------------------------------------------
304
SID_MIDI_D_Hlp_SetSeq
305
	;; store drum number in PRODL
306
	movwf	PRODL
307
 
308
	;; if number >= 8: set to 8 (sequence off)
309
	movlw	8
310
	cpfslt	PRODL, ACCESS
311
	movwf PRODL
312
 
313
	;; set new sequence
314
 
315
	;; patch/shadow buffer
316
	movff	PRODL, SID_PATCH_BUFFER + SID_Ix_D_SEQ_NUM
317
	movff	PRODL, SID_PATCH_BUFFER_SHADOW + SID_Ix_D_SEQ_NUM
318
 
319
	;; forward to edit buffer if SID selected
320
	call	CS_MENU_MS_GetSIDNumber
321
	xorwf	CS_MENU_EDIT_BUFFER_SID, W
322
	skpnz
323
	movff	PRODL, SID_EDIT_BUFFER + SID_Ix_D_SEQ_NUM
324
 
325
	return