• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • libtdemid
 

libtdemid

  • libtdemid
synthout.cpp
1 /**************************************************************************
2 
3  synthout.cpp - class synthOut which handles the /dev/sequencer device
4  for synths (as AWE32)
5  This file is part of LibKMid 0.9.5
6  Copyright (C) 1997,98 Antonio Larrosa Jimenez and P.J.Leonard
7  1999,2000 Antonio Larrosa Jimenez
8  LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libtdemid.html
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Library General Public
12  License as published by the Free Software Foundation; either
13  version 2 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Library General Public License for more details.
19 
20  You should have received a copy of the GNU Library General Public License
21  along with this library; see the file COPYING.LIB. If not, write to
22  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23  Boston, MA 02110-1301, USA.
24 
25  Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
26 
27 ***************************************************************************/
28 #include "synthout.h"
29 #include <unistd.h>
30 #include <fcntl.h>
31 #include <stdio.h>
32 #include "sndcard.h"
33 #include <sys/ioctl.h>
34 #include <errno.h>
35 #include <string.h>
36 #include <sys/param.h>
37 #include "awe_sup.h"
38 #include "midispec.h"
39 
40 #ifdef HAVE_CONFIG_H
41 #include <config.h>
42 #endif
43 
44 SEQ_USE_EXTBUF();
45 
46 SynthOut::SynthOut(int d)
47 {
48  seqfd = -1;
49  devicetype=KMID_SYNTH;
50  device= d;
51  _ok=1;
52 }
53 
54 SynthOut::~SynthOut()
55 {
56  closeDev();
57 }
58 
59 void SynthOut::openDev (int sqfd)
60 {
61  _ok=1;
62  seqfd = sqfd;
63  if (seqfd==-1)
64  {
65  printfdebug("ERROR: Could not open /dev/sequencer\n");
66  return;
67  }
68 #ifdef HAVE_OSS_SUPPORT
69  /*
70  int i=1;
71  ioctl(seqfd,SNDCTL_SEQ_THRESHOLD,i);
72  printfdebug("Threshold : %d\n",i);
73  */
74 #ifdef SYNTHOUTDEBUG
75  printfdebug("Number of synth devices : %d\n",ndevs);
76  printfdebug("Number of midi ports : %d\n",nmidiports);
77  printfdebug("Rate : %d\n",m_rate);
78 #endif
79 
80 #ifdef HAVE_AWE32
81 
82  struct synth_info info;
83 
84  // Should really collect the possible devices and let the user choose ?
85 
86  info.device = device;
87 
88  if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1)
89  printfdebug(" ioctl SNDCTL_SYNTH_INFO FAILED \n");
90 
91  if (info.synth_type == SYNTH_TYPE_SAMPLE
92  && info.synth_subtype == SAMPLE_TYPE_AWE32)
93  {
94 
95  // Enable layered patches ....
96  AWE_SET_CHANNEL_MODE(device,1);
97 #ifdef SYNTHOUTDEBUG
98  printfdebug(" Found AWE32 dev=%d \n",device);
99 #endif
100  }
101 #endif // HAVE_AWE32
102 #endif // HAVE_OSS_SUPPORT
103 
104 }
105 
106 void SynthOut::closeDev (void)
107 {
108  if (!ok()) return;
109  //if (seqfd>=0) close(seqfd);
110  seqfd=-1;
111 }
112 
113 void SynthOut::initDev (void)
114 {
115 #ifdef HAVE_OSS_SUPPORT
116  int chn;
117  if (!ok()) return;
118  uchar gm_reset[5]={0x7e, 0x7f, 0x09, 0x01, 0xf7};
119  sysex(gm_reset, sizeof(gm_reset));
120  for (chn=0;chn<16;chn++)
121  {
122  chnmute[chn]=0;
123  chnPatchChange(chn,0);
124  chnPressure(chn,127);
125  chnPitchBender(chn, 0x00, 0x40);
126  chnController(chn, CTL_MAIN_VOLUME,127);
127  chnController(chn, CTL_EXT_EFF_DEPTH, 0);
128  chnController(chn, CTL_CHORUS_DEPTH, 0);
129  chnController(chn, 0x4a, 127);
130  }
131 #endif
132 }
133 
134 void SynthOut::noteOn (uchar chn, uchar note, uchar vel)
135 {
136  if (vel==0)
137  {
138  noteOff(chn,note,vel);
139  }
140  else
141  {
142  SEQ_START_NOTE(device, map->channel(chn),
143  map->key(chn,chnpatch[chn],note),
144  vel);
145  }
146 #ifdef SYNTHOUTDEBUG
147  printfdebug("Note ON >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
148 #endif
149 }
150 
151 void SynthOut::noteOff (uchar chn, uchar note, uchar)
152 {
153  SEQ_STOP_NOTE(device, map->channel(chn),
154  map->key(chn,chnpatch[chn],note), 0);
155 #ifdef SYNTHOUTDEBUG
156  printfdebug("Note OFF >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
157 #endif
158 }
159 
160 void SynthOut::keyPressure (uchar chn, uchar note, uchar vel)
161 {
162  SEQ_KEY_PRESSURE(device, map->channel(chn), map->key(chn,chnpatch[chn],note),vel);
163 }
164 
165 void SynthOut::chnPatchChange (uchar chn, uchar patch)
166 {
167  SEQ_SET_PATCH(device,map->channel(chn),map->patch(chn,patch));
168  chnpatch[chn]=patch;
169 }
170 
171 void SynthOut::chnPressure (uchar chn, uchar vel)
172 {
173  SEQ_CHN_PRESSURE(device, map->channel(chn) , vel);
174  chnpressure[chn]=vel;
175 }
176 
177 void SynthOut::chnPitchBender(uchar chn,uchar lsb, uchar msb)
178 {
179  chnbender[chn]=((int)msb<<7) | (lsb & 0x7F);
180  SEQ_BENDER(device, map->channel(chn), chnbender[chn]);
181 }
182 
183 void SynthOut::chnController (uchar chn, uchar ctl, uchar v)
184 {
185  if ((ctl==11)||(ctl==7))
186  {
187  v=(v*volumepercentage)/100;
188  if (v>127) v=127;
189  }
190 
191  SEQ_CONTROL(device, map->channel(chn), ctl, v);
192  chncontroller[chn][ctl]=v;
193 }
194 
195 void SynthOut::sysex(uchar *, ulong )
196 {
197  // AWE32 doesn't respond to sysex (AFAIK)
198 /*
199 #ifndef HAVE_AWE32
200  ulong i=0;
201  SEQ_MIDIOUT(device, MIDI_SYSTEM_PREFIX);
202  while (i<size)
203  {
204  SEQ_MIDIOUT(device, *data);
205  data++;
206  i++;
207  };
208  printfdebug("sysex\n");
209 #endif
210 */
211 }
MidiMapper::channel
uchar channel(uchar chn)
Returns the channel which chn should be mapped to.
Definition: midimapper.h:177
MidiMapper::patch
uchar patch(uchar chn, uchar pgm)
Returns the patch which pgm used on channel chn should be mapped to.
Definition: midimapper.cpp:431
MidiMapper::key
uchar key(uchar chn, uchar pgm, uchar note)
Returns the key that key note playing a pgm patch on channel chn should be mapped to.
Definition: midimapper.cpp:423
MidiOut::ok
int ok(void)
Returns true if everything's ok and false if there has been any problem.
Definition: midiout.h:231
SynthOut::openDev
void openDev(int sqfd)
See MidiOut::openDev()
Definition: synthout.cpp:59
SynthOut::chnPitchBender
void chnPitchBender(uchar chn, uchar lsb, uchar msb)
See MidiOut::chnPitchBender()
Definition: synthout.cpp:177
SynthOut::noteOn
void noteOn(uchar chn, uchar note, uchar vel)
See MidiOut::noteOn()
Definition: synthout.cpp:134
SynthOut::~SynthOut
~SynthOut()
Destructor.
Definition: synthout.cpp:54
SynthOut::chnPressure
void chnPressure(uchar chn, uchar vel)
See MidiOut::chnPressure()
Definition: synthout.cpp:171
SynthOut::closeDev
void closeDev(void)
See MidiOut::closeDev()
Definition: synthout.cpp:106
SynthOut::keyPressure
void keyPressure(uchar chn, uchar note, uchar vel)
See MidiOut::keyPressure()
Definition: synthout.cpp:160
SynthOut::chnPatchChange
void chnPatchChange(uchar chn, uchar patch)
See MidiOut::chnPatchChange()
Definition: synthout.cpp:165
SynthOut::SynthOut
SynthOut(int d=0)
Constructor.
Definition: synthout.cpp:46
SynthOut::initDev
void initDev(void)
See MidiOut::initDev()
Definition: synthout.cpp:113
SynthOut::sysex
void sysex(uchar *data, ulong size)
It's an empty function, as AWE devices don't support System Exclusive messages.
Definition: synthout.cpp:195
SynthOut::chnController
void chnController(uchar chn, uchar ctl, uchar v)
See MidiOut::chnController()
Definition: synthout.cpp:183
SynthOut::noteOff
void noteOff(uchar chn, uchar note, uchar vel)
See MidiOut::noteOff()
Definition: synthout.cpp:151

libtdemid

Skip menu "libtdemid"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

libtdemid

Skip menu "libtdemid"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for libtdemid by doxygen 1.9.1
This website is maintained by Timothy Pearson.