synthout.cc
/**************************************************************************
synthout.cc - class synthOut which handles the /dev/sequencer device
for synths (as AWE32)
This file is part of LibKMid 0.9.5
Copyright (C) 1997,98 Antonio Larrosa Jimenez and P.J.Leonard
1999,2000 Antonio Larrosa Jimenez
LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
***************************************************************************/
#include "synthout.h"
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include "sndcard.h"
#include <sys/ioctl.h>
#include <errno.h>
#include <string.h>
#include <sys/param.h>
#include "awe_sup.h"
#include "midispec.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
SEQ_USE_EXTBUF();
SynthOut::SynthOut(int d)
{
seqfd = -1;
devicetype=KMID_SYNTH;
device= d;
_ok=1;
}
SynthOut::~SynthOut()
{
closeDev();
}
void SynthOut::openDev (int sqfd)
{
_ok=1;
seqfd = sqfd;
if (seqfd==-1)
{
printfdebug("ERROR: Could not open /dev/sequencer\n");
return;
}
#ifdef HAVE_OSS_SUPPORT
/*
int i=1;
ioctl(seqfd,SNDCTL_SEQ_THRESHOLD,i);
printfdebug("Threshold : %d\n",i);
*/
#ifdef SYNTHOUTDEBUG
printfdebug("Number of synth devices : %d\n",ndevs);
printfdebug("Number of midi ports : %d\n",nmidiports);
printfdebug("Rate : %d\n",m_rate);
#endif
#ifdef HAVE_AWE32
struct synth_info info;
// Should really collect the possible devices and let the user choose ?
info.device = device;
if (ioctl (seqfd, SNDCTL_SYNTH_INFO, &info) == -1)
printfdebug(" ioctl SNDCTL_SYNTH_INFO FAILED \n");
if (info.synth_type == SYNTH_TYPE_SAMPLE
&& info.synth_subtype == SAMPLE_TYPE_AWE32)
{
// Enable layered patches ....
AWE_SET_CHANNEL_MODE(device,1);
#ifdef SYNTHOUTDEBUG
printfdebug(" Found AWE32 dev=%d \n",device);
#endif
}
#endif // HAVE_AWE32
#endif // HAVE_OSS_SUPPORT
}
void SynthOut::closeDev (void)
{
if (!ok()) return;
//if (seqfd>=0) close(seqfd);
seqfd=-1;
}
void SynthOut::initDev (void)
{
#ifdef HAVE_OSS_SUPPORT
int chn;
if (!ok()) return;
uchar gm_reset[5]={0x7e, 0x7f, 0x09, 0x01, 0xf7};
sysex(gm_reset, sizeof(gm_reset));
for (chn=0;chn<16;chn++)
{
chnmute[chn]=0;
chnPatchChange(chn,0);
chnPressure(chn,127);
chnPitchBender(chn, 0x00, 0x40);
chnController(chn, CTL_MAIN_VOLUME,127);
chnController(chn, CTL_EXT_EFF_DEPTH, 0);
chnController(chn, CTL_CHORUS_DEPTH, 0);
chnController(chn, 0x4a, 127);
}
#endif
}
void SynthOut::noteOn (uchar chn, uchar note, uchar vel)
{
if (vel==0)
{
noteOff(chn,note,vel);
}
else
{
SEQ_START_NOTE(device, map->channel(chn),
map->key(chn,chnpatch[chn],note),
vel);
}
#ifdef SYNTHOUTDEBUG
printfdebug("Note ON >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
#endif
}
void SynthOut::noteOff (uchar chn, uchar note, uchar)
{
SEQ_STOP_NOTE(device, map->channel(chn),
map->key(chn,chnpatch[chn],note), 0);
#ifdef SYNTHOUTDEBUG
printfdebug("Note OFF >\t chn : %d\tnote : %d\tvel: %d\n",chn,note,vel);
#endif
}
void SynthOut::keyPressure (uchar chn, uchar note, uchar vel)
{
SEQ_KEY_PRESSURE(device, map->channel(chn), map->key(chn,chnpatch[chn],note),vel);
}
void SynthOut::chnPatchChange (uchar chn, uchar patch)
{
SEQ_SET_PATCH(device,map->channel(chn),map->patch(chn,patch));
chnpatch[chn]=patch;
}
void SynthOut::chnPressure (uchar chn, uchar vel)
{
SEQ_CHN_PRESSURE(device, map->channel(chn) , vel);
chnpressure[chn]=vel;
}
void SynthOut::chnPitchBender(uchar chn,uchar lsb, uchar msb)
{
chnbender[chn]=((int)msb<<7) | (lsb & 0x7F);
SEQ_BENDER(device, map->channel(chn), chnbender[chn]);
}
void SynthOut::chnController (uchar chn, uchar ctl, uchar v)
{
if ((ctl==11)||(ctl==7))
{
v=(v*volumepercentage)/100;
if (v>127) v=127;
}
SEQ_CONTROL(device, map->channel(chn), ctl, v);
chncontroller[chn][ctl]=v;
}
void SynthOut::sysex(uchar *, ulong )
{
// AWE32 doesn't respond to sysex (AFAIK)
/*
#ifndef HAVE_AWE32
ulong i=0;
SEQ_MIDIOUT(device, MIDI_SYSTEM_PREFIX);
while (i<size)
{
SEQ_MIDIOUT(device, *data);
data++;
i++;
};
printfdebug("sysex\n");
#endif
*/
}
SynthOut::chnPitchBender
void chnPitchBender(uchar chn, uchar lsb, uchar msb)
See MidiOut::chnPitchBender()
Definition: synthout.cc:177
SynthOut::openDev
void openDev(int sqfd)
See MidiOut::openDev()
Definition: synthout.cc:59
SynthOut::sysex
void sysex(uchar *data, ulong size)
It's an empty function, as AWE devices don't support System Exclusive messages.
Definition: synthout.cc:195
SynthOut::chnPatchChange
void chnPatchChange(uchar chn, uchar patch)
See MidiOut::chnPatchChange()
Definition: synthout.cc:165
SynthOut::noteOff
void noteOff(uchar chn, uchar note, uchar vel)
See MidiOut::noteOff()
Definition: synthout.cc:151
SynthOut::initDev
void initDev(void)
See MidiOut::initDev()
Definition: synthout.cc:113
SynthOut::chnPressure
void chnPressure(uchar chn, uchar vel)
See MidiOut::chnPressure()
Definition: synthout.cc:171
SynthOut::chnController
void chnController(uchar chn, uchar ctl, uchar v)
See MidiOut::chnController()
Definition: synthout.cc:183
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.cc:431
MidiOut::ok
int ok(void)
Returns true if everything's ok and false if there has been any problem.
Definition: midiout.h:231
SynthOut::noteOn
void noteOn(uchar chn, uchar note, uchar vel)
See MidiOut::noteOn()
Definition: synthout.cc:134
SynthOut::~SynthOut
~SynthOut()
Destructor.
Definition: synthout.cc:54
SynthOut::SynthOut
SynthOut(int d=0)
Constructor.
Definition: synthout.cc:46
SynthOut::closeDev
void closeDev(void)
See MidiOut::closeDev()
Definition: synthout.cc:106
SynthOut::keyPressure
void keyPressure(uchar chn, uchar note, uchar vel)
See MidiOut::keyPressure()
Definition: synthout.cc:160
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.cc:423

KDE Home | KDE Accessibility Home | Description of Access Keys