1
/**************************************************************************
3
synthout.cc - class synthOut which handles the /dev/sequencer device
5
Copyright (C) 1997,98,99 Antonio Larrosa Jimenez
6
P.J.Leonard (P.J.Leonard@bath.ac.uk)
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program; if not, write to the Free Software
20
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22
Send comments and bug fixes to antlarr@arrakis.es
23
or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
25
***************************************************************************/
31
#include <sys/ioctl.h>
34
#include <sys/param.h>
37
#include "../version.h"
41
SynthOut::SynthOut(int d)
44
devicetype=KMID_SYNTH;
46
#ifdef HANDLETIMEINDEVICES
60
void SynthOut::openDev (int sqfd)
66
printfdebug("ERROR: Could not open /dev/sequencer\n");
69
#ifdef HANDLETIMEINDEVICES
70
ioctl(seqfd,SNDCTL_SEQ_NRSYNTHS,&ndevs);
71
ioctl(seqfd,SNDCTL_SEQ_NRMIDIS,&nmidiports);
73
int r=ioctl(seqfd,SNDCTL_SEQ_CTRLRATE,&rate);
74
if ((r==-1)||(rate<=0)) rate=HZ;
75
convertrate=1000/rate;
78
ioctl(seqfd,SNDCTL_SEQ_THRESHOLD,i);
79
printfdebug("Threshold : %d\n",i);
82
printfdebug("Number of synth devices : %d\n",ndevs);
83
printfdebug("Number of midi ports : %d\n",nmidiports);
84
printfdebug("Rate : %d\n",rate);
93
struct synth_info info;
95
// Should really collect the possible devices and let the user choose ?
99
if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1)
100
printfdebug(" ioctl SNDCTL_SYNTH_INFO FAILED \n");
102
if (info.synth_type == SYNTH_TYPE_SAMPLE
103
&& info.synth_subtype == SAMPLE_TYPE_AWE32)
106
// Enable layered patches ....
107
AWE_SET_CHANNEL_MODE(device,1);
109
printfdebug(" Found AWE32 dev=%d \n",device);
116
void SynthOut::closeDev (void)
119
#ifdef HANDLETIMEINDEVICES
123
//if (seqfd>=0) close(seqfd);
127
void SynthOut::initDev (void)
131
#ifdef HANDLETIMEINDEVICES
135
uchar gm_reset[5]={0x7e, 0x7f, 0x09, 0x01, 0xf7};
136
sysex(gm_reset, sizeof(gm_reset));
137
for (chn=0;chn<16;chn++)
140
chnPatchChange(chn,0);
141
chnPressure(chn,127);
142
chnPitchBender(chn, 0x00, 0x40);
143
chnController(chn, CTL_MAIN_VOLUME,127);
144
chnController(chn, CTL_EXT_EFF_DEPTH, 0);
145
chnController(chn, CTL_CHORUS_DEPTH, 0);
146
chnController(chn, 0x4a, 127);
150
void SynthOut::noteOn (uchar chn, uchar note, uchar vel)
154
noteOff(chn,note,vel);
158
SEQ_START_NOTE(device, map->channel(chn),
159
map->key(chn,chnpatch[chn],note),
163
printfdebug("Note ON >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
167
void SynthOut::noteOff (uchar chn, uchar note, uchar)
169
SEQ_STOP_NOTE(device, map->channel(chn),
170
map->key(chn,chnpatch[chn],note), 0);
172
printfdebug("Note OFF >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
176
void SynthOut::keyPressure (uchar chn, uchar note, uchar vel)
178
SEQ_KEY_PRESSURE(device, map->channel(chn), map->key(chn,chnpatch[chn],note),vel);
181
void SynthOut::chnPatchChange (uchar chn, uchar patch)
183
SEQ_SET_PATCH(device,map->channel(chn),map->patch(chn,patch));
187
void SynthOut::chnPressure (uchar chn, uchar vel)
189
SEQ_CHN_PRESSURE(device, map->channel(chn) , vel);
190
chnpressure[chn]=vel;
193
void SynthOut::chnPitchBender(uchar chn,uchar lsb, uchar msb)
195
chnbender[chn]=((int)msb<<7) | (lsb & 0x7F);
196
SEQ_BENDER(device, map->channel(chn), chnbender[chn]);
199
void SynthOut::chnController (uchar chn, uchar ctl, uchar v)
201
if ((ctl==11)||(ctl==7))
203
v=(v*volumepercentage)/100;
207
SEQ_CONTROL(device, map->channel(chn), ctl, v);
208
chncontroller[chn][ctl]=v;
211
void SynthOut::sysex(uchar *, ulong )
213
// AWE32 doesn't respond to sysex (AFAIK)
217
SEQ_MIDIOUT(device, MIDI_SYSTEM_PREFIX);
220
SEQ_MIDIOUT(device, *data);
224
printfdebug("sysex\n");