~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to kmid/player/synthout.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
 
 
3
    synthout.cc   - class synthOut which handles the /dev/sequencer device
 
4
                        for synths (as AWE32)
 
5
    Copyright (C) 1997,98,99  Antonio Larrosa Jimenez
 
6
                        P.J.Leonard (P.J.Leonard@bath.ac.uk)
 
7
 
 
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.
 
12
 
 
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.
 
17
 
 
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.
 
21
 
 
22
    Send comments and bug fixes to antlarr@arrakis.es
 
23
    or to Antonio Larrosa, Rio Arnoya, 10 5B, 29006 Malaga, Spain
 
24
 
 
25
***************************************************************************/
 
26
#include "synthout.h"
 
27
#include <unistd.h>
 
28
#include <fcntl.h>
 
29
#include <stdio.h>
 
30
#include "sndcard.h"
 
31
#include <sys/ioctl.h>
 
32
#include <errno.h>
 
33
#include <string.h>
 
34
#include <sys/param.h>
 
35
#include "awe_sup.h"
 
36
#include "midispec.h"
 
37
#include "../version.h"
 
38
 
 
39
SEQ_USE_EXTBUF();
 
40
 
 
41
SynthOut::SynthOut(int d)
 
42
{
 
43
  seqfd = -1;
 
44
  devicetype=KMID_SYNTH;
 
45
  device= d;
 
46
#ifdef HANDLETIMEINDEVICES
 
47
  count=0.0;
 
48
  lastcount=0.0;
 
49
  rate=100;
 
50
#endif
 
51
  _ok=1;
 
52
}
 
53
 
 
54
SynthOut::~SynthOut()
 
55
{
 
56
  delete map;
 
57
  closeDev();
 
58
}
 
59
 
 
60
void SynthOut::openDev (int sqfd)
 
61
{
 
62
  _ok=1;
 
63
  seqfd = sqfd;
 
64
  if (seqfd==-1)
 
65
  {
 
66
    printfdebug("ERROR: Could not open /dev/sequencer\n");
 
67
    return;
 
68
  }
 
69
#ifdef HANDLETIMEINDEVICES
 
70
  ioctl(seqfd,SNDCTL_SEQ_NRSYNTHS,&ndevs);
 
71
  ioctl(seqfd,SNDCTL_SEQ_NRMIDIS,&nmidiports);
 
72
  rate=0;
 
73
  int r=ioctl(seqfd,SNDCTL_SEQ_CTRLRATE,&rate);
 
74
  if ((r==-1)||(rate<=0)) rate=HZ;
 
75
  convertrate=1000/rate;
 
76
  /*
 
77
     int i=1;
 
78
     ioctl(seqfd,SNDCTL_SEQ_THRESHOLD,i);
 
79
     printfdebug("Threshold : %d\n",i);
 
80
   */
 
81
#ifdef SYNTHOUTDEBUG
 
82
  printfdebug("Number of synth devices : %d\n",ndevs);
 
83
  printfdebug("Number of midi ports : %d\n",nmidiports);
 
84
  printfdebug("Rate : %d\n",rate);
 
85
#endif
 
86
 
 
87
  count=0.0;
 
88
  lastcount=0.0;
 
89
#endif
 
90
 
 
91
#ifdef HAVE_AWE32  
 
92
 
 
93
  struct synth_info info;
 
94
 
 
95
  // Should really collect the possible devices and let the user choose ?
 
96
 
 
97
  info.device = device;
 
98
 
 
99
  if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1) 
 
100
    printfdebug(" ioctl  SNDCTL_SYNTH_INFO FAILED \n");
 
101
 
 
102
  if (info.synth_type == SYNTH_TYPE_SAMPLE
 
103
      && info.synth_subtype == SAMPLE_TYPE_AWE32) 
 
104
  {
 
105
 
 
106
    // Enable layered patches ....
 
107
    AWE_SET_CHANNEL_MODE(device,1);
 
108
#ifdef SYNTHOUTDEBUG
 
109
    printfdebug(" Found AWE32 dev=%d \n",device);
 
110
#endif
 
111
  }
 
112
#endif
 
113
 
 
114
}
 
115
 
 
116
void SynthOut::closeDev (void)
 
117
{
 
118
  if (!ok()) return;
 
119
#ifdef HANDLETIMEINDEVICES
 
120
  SEQ_STOP_TIMER();
 
121
  SEQ_DUMPBUF();
 
122
#endif
 
123
  //if (seqfd>=0) close(seqfd);
 
124
  seqfd=-1;
 
125
}
 
126
 
 
127
void SynthOut::initDev (void)
 
128
{
 
129
  int chn;
 
130
  if (!ok()) return;
 
131
#ifdef HANDLETIMEINDEVICES
 
132
  count=0.0;
 
133
  lastcount=0.0;
 
134
#endif
 
135
  uchar gm_reset[5]={0x7e, 0x7f, 0x09, 0x01, 0xf7};
 
136
  sysex(gm_reset, sizeof(gm_reset));
 
137
  for (chn=0;chn<16;chn++)
 
138
  {
 
139
    chnmute[chn]=0;
 
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);
 
147
  }
 
148
}
 
149
 
 
150
void SynthOut::noteOn  (uchar chn, uchar note, uchar vel)
 
151
{
 
152
  if (vel==0)
 
153
  {
 
154
    noteOff(chn,note,vel);
 
155
  }
 
156
  else
 
157
  {
 
158
    SEQ_START_NOTE(device, map->channel(chn),
 
159
        map->key(chn,chnpatch[chn],note),
 
160
        vel);
 
161
  }
 
162
#ifdef SYNTHOUTDEBUG
 
163
  printfdebug("Note ON >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
 
164
#endif
 
165
}
 
166
 
 
167
void SynthOut::noteOff (uchar chn, uchar note, uchar)
 
168
{
 
169
  SEQ_STOP_NOTE(device, map->channel(chn),
 
170
      map->key(chn,chnpatch[chn],note), 0);
 
171
#ifdef SYNTHOUTDEBUG
 
172
  printfdebug("Note OFF >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
 
173
#endif
 
174
}
 
175
 
 
176
void SynthOut::keyPressure (uchar chn, uchar note, uchar vel)
 
177
{
 
178
  SEQ_KEY_PRESSURE(device, map->channel(chn), map->key(chn,chnpatch[chn],note),vel);
 
179
}
 
180
 
 
181
void SynthOut::chnPatchChange (uchar chn, uchar patch)
 
182
{
 
183
  SEQ_SET_PATCH(device,map->channel(chn),map->patch(chn,patch)); 
 
184
  chnpatch[chn]=patch;
 
185
}
 
186
 
 
187
void SynthOut::chnPressure (uchar chn, uchar vel)
 
188
{
 
189
  SEQ_CHN_PRESSURE(device, map->channel(chn) , vel);
 
190
  chnpressure[chn]=vel;
 
191
}
 
192
 
 
193
void SynthOut::chnPitchBender(uchar chn,uchar lsb, uchar msb)
 
194
{
 
195
  chnbender[chn]=((int)msb<<7) | (lsb & 0x7F);
 
196
  SEQ_BENDER(device, map->channel(chn), chnbender[chn]);
 
197
}
 
198
 
 
199
void SynthOut::chnController (uchar chn, uchar ctl, uchar v) 
 
200
{
 
201
  if ((ctl==11)||(ctl==7))
 
202
  {
 
203
    v=(v*volumepercentage)/100;
 
204
    if (v>127) v=127;
 
205
  }
 
206
 
 
207
  SEQ_CONTROL(device, map->channel(chn), ctl, v);
 
208
  chncontroller[chn][ctl]=v;
 
209
}
 
210
 
 
211
void SynthOut::sysex(uchar *, ulong )
 
212
{
 
213
  // AWE32 doesn't respond to sysex (AFAIK)
 
214
/*  
 
215
#ifndef HAVE_AWE32
 
216
  ulong i=0;
 
217
  SEQ_MIDIOUT(device, MIDI_SYSTEM_PREFIX);
 
218
  while (i<size)
 
219
  {
 
220
    SEQ_MIDIOUT(device, *data);
 
221
    data++;
 
222
    i++;
 
223
  };
 
224
  printfdebug("sysex\n");
 
225
#endif
 
226
*/
 
227
}