home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / libkmid / midiout.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-10-08  |  6.9 KB  |  252 lines

  1. /*  midiout.h    - class midiOut which handles the /dev/sequencer device
  2.     This file is part of LibKMid 0.9.5
  3.     Copyright (C) 1997,98,99,2000  Antonio Larrosa Jimenez
  4.     LibKMid's homepage : http://www.arrakis.es/~rlarrosa/libkmid.html
  5.  
  6.     This library is free software; you can redistribute it and/or
  7.     modify it under the terms of the GNU Library General Public
  8.     License as published by the Free Software Foundation; either
  9.     version 2 of the License, or (at your option) any later version.
  10.  
  11.     This library is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.     Library General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU Library General Public License
  17.     along with this library; see the file COPYING.LIB.  If not, write to
  18.     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.     Boston, MA 02110-1301, USA.
  20.  
  21.     Send comments and bug fixes to Antonio Larrosa <larrosa@kde.org>
  22.  
  23. ***************************************************************************/
  24. #ifndef _MIDIOUT_H
  25. #define _MIDIOUT_H
  26.  
  27. #include <libkmid/dattypes.h>
  28. #include <libkmid/deviceman.h>
  29. #include <libkmid/midimapper.h>
  30. #include <stdio.h>
  31.  
  32. /**
  33.  * External MIDI port output class . This class is used to send midi
  34.  * events to external midi devices.
  35.  *
  36.  * MidiOut is inherited by other MIDI devices classes
  37.  * (like SynthOut or FMOut) to support a common API.
  38.  *
  39.  * In general, you don't want to use MidiOut directly, but within a
  40.  * DeviceManager object, which is the preferred way to generate music.
  41.  *
  42.  * If you want to add support for other devices (I don't think
  43.  * there are any) you just have to create a class that inherits from MidiOut
  44.  * and create one object of your new class in
  45.  * DeviceManager::initManager().
  46.  *
  47.  * @short Sends MIDI events to external MIDI devices
  48.  * @version 0.9.5 17/01/2000
  49.  * @author Antonio Larrosa Jimenez <larrosa@kde.org>
  50.  */
  51. class MidiOut
  52. {
  53.   private:
  54.     class MidiOutPrivate;
  55.     MidiOutPrivate *d;
  56.  
  57.   protected:
  58.  
  59.   /**
  60.    * @internal
  61.    * This is the /dev/sequencer file handler.
  62.    * Remember _not_to_close_ it on MidiOut, but just on DeviceManager
  63.    */
  64.   int seqfd;
  65.  
  66.   int device;
  67.  
  68.   int devicetype;
  69.  
  70.   int volumepercentage;
  71.  
  72.   MidiMapper *map;
  73.  
  74.   uchar    chnpatch [16];
  75.   int      chnbender [16];
  76.   uchar    chnpressure [16];
  77.   uchar    chncontroller [16][256];
  78.   int    chnmute [16];
  79.  
  80.   int    _ok;
  81.  
  82.   void seqbuf_dump (void);
  83.   void seqbuf_clean(void);
  84.  
  85.   public:
  86.  
  87.   /**
  88.    * Constructor. After constructing a MidiOut device, you must open it
  89.    * (using openDev() ). Additionally you may want to initialize it
  90.    * (with initDev() ),
  91.    */
  92.   MidiOut(int d=0);
  93.  
  94.   /**
  95.    * Destructor. It doesn't matter if you close the device ( closeDev() )
  96.    * before you destruct the object because in other case, it will be closed
  97.    * here.
  98.    */
  99.   virtual ~MidiOut();
  100.  
  101.   /**
  102.    * Opens the device. This is generally called from DeviceManager , so you
  103.    * shouldn't call this yourself (except if you created the MidiOut object
  104.    * yourself.
  105.    * @param sqfd a file descriptor of /dev/sequencer
  106.    * @see closeDev
  107.    * @see initDev
  108.    */
  109.   virtual void openDev    (int sqfd);
  110.  
  111.   /**
  112.    * Closes the device. It basically tells the device (the file descriptor)
  113.    * is going to be closed.
  114.    * @see openDev
  115.    */
  116.   virtual void closeDev    ();
  117.  
  118.   /**
  119.    * Initializes the device sending generic standard midi events and controllers,
  120.    * such as changing the patches of each channel to an Acoustic Piano (000),
  121.    * setting the volume to a normal value, etc.
  122.    */
  123.   virtual void initDev    ();
  124.  
  125.   /**
  126.    * @return the device type of the object. This is to identify the
  127.    * inherited class that a given object is polymorphed to.
  128.    * The returned value is one of these :
  129.    *
  130.    * @li KMID_EXTERNAL_MIDI if it's a MidiOut object
  131.    * @li KMID_SYNTH if it's a SynthOut object (as an AWE device)
  132.    * @li KMID_FM if it's a FMOut object
  133.    * @li KMID_GUS if it's a GUSOut object
  134.    *
  135.    * which are defined in midispec.h
  136.    *
  137.    * @see deviceName
  138.    */
  139.   int          deviceType () const { return devicetype; }
  140.  
  141.   /**
  142.    * Returns the name and type of this MIDI device.
  143.    * @see deviceType
  144.    */
  145.   const char * deviceName (void) const;
  146.  
  147.   /**
  148.    * Sets a MidiMapper object to be used to modify the midi events before
  149.    * sending them.
  150.    *
  151.    * @param map the MidiMapper to use.
  152.    *
  153.    * @see MidiMapper
  154.    * @see midiMapFilename
  155.    */
  156.   void setMidiMapper    ( MidiMapper *map );
  157.  
  158.   /**
  159.    * See DeviceManager::noteOn()
  160.    */
  161.   virtual void noteOn    ( uchar chn, uchar note, uchar vel );
  162.  
  163.   /**
  164.    * See DeviceManager::noteOff()
  165.    */
  166.   virtual void noteOff    ( uchar chn, uchar note, uchar vel );
  167.  
  168.   /**
  169.    * See DeviceManager::keyPressure()
  170.    */
  171.   virtual void keyPressure    ( uchar chn, uchar note, uchar vel );
  172.  
  173.   /**
  174.    * See DeviceManager::chnPatchChange()
  175.    */
  176.   virtual void chnPatchChange    ( uchar chn, uchar patch );
  177.  
  178.   /**
  179.    * See DeviceManager::chnPressure()
  180.    */
  181.   virtual void chnPressure    ( uchar chn, uchar vel );
  182.  
  183.   /**
  184.    * See DeviceManager::chnPitchBender()
  185.    */
  186.   virtual void chnPitchBender    ( uchar chn, uchar lsb,  uchar msb );
  187.  
  188.   /**
  189.    * See DeviceManager::chnController()
  190.    */
  191.   virtual void chnController    ( uchar chn, uchar ctl , uchar v );
  192.  
  193.   /**
  194.    * See DeviceManager::sysex()
  195.    */
  196.   virtual void sysex        ( uchar *data,ulong size);
  197.  
  198.   /**
  199.    * Send a All Notes Off event to every channel
  200.    */
  201.   void allNotesOff(void);
  202.  
  203.   /**
  204.    * Mutes all notes being played on a given channel.
  205.    * @param chn the channel
  206.    */
  207.   virtual void channelSilence    ( uchar chn );
  208.  
  209.   /**
  210.    * Mute or "unmute" a given channel .
  211.    * @param chn channel to work on
  212.    * @param b if true, the device will ignore subsequent notes played on the chn
  213.    * channel, and mute all notes being played on it. If b is false, the channel
  214.    * is back to work.
  215.    */
  216.   virtual void channelMute    ( uchar chn, int b );
  217.  
  218.   /**
  219.    * Change all channel volume events multiplying it by this percentage correction
  220.    * Instead of forcing a channel to a fixed volume, this method allows to
  221.    * music to fade out even when it was being played softly.
  222.    * @param volper is an integer value, where 0 is quiet, 100 is used to send
  223.    * an unmodified value, 200 play music twice louder than it should, etc.
  224.    */
  225.   virtual void setVolumePercentage ( int volper )
  226.   { volumepercentage = volper; }
  227.  
  228.   /**
  229.    * Returns true if everything's ok and false if there has been any problem
  230.    */
  231.   int ok (void)
  232.   { if (seqfd<0) return 0;
  233.     return (_ok>0);
  234.   }
  235.  
  236.   /**
  237.    * Returns the path to the file where the current used MidiMapper object
  238.    * reads the configuration from, or an empty string if there's no MidiMapper.
  239.    */
  240.   const char *midiMapFilename ();
  241.  
  242.   /**
  243.    * Sends the buffer to the device and returns when it's played, so you can
  244.    * synchronize
  245.    * XXX: sync should be virtual after next bic release
  246.    */
  247.   void sync(int i=0);
  248.  
  249. };
  250.  
  251. #endif
  252.