KMIDI.cc

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2000  Dancer A.L Vesperman
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #ifdef HAVE_CONFIG_H
00020 #  include <config.h>
00021 #endif
00022 
00023 #ifdef XWIN
00024 
00025 #include "KMIDI.h"
00026 
00027 #ifndef ALPHA_LINUX_CXX
00028 #  include <unistd.h>
00029 #  include <csignal>
00030 #endif
00031 #include "fnames.h"
00032 
00033 #include "Configuration.h"
00034 extern  Configuration *config;
00035 
00036 
00037 #if HAVE_LIBKMIDI
00038 
00039 int kmidi_device_selection(void)
00040 {
00041   int num_devices=kMidDevices();
00042 
00043   if(!num_devices)
00044     return -1;
00045   cout << "Device\tType\tIdentity" << endl;
00046   cout << "-1\tnone\tdisable kmidi" << endl;
00047   for(int i=0;i<num_devices;i++)
00048     {
00049     cout << i <<"\t"<< kMidType(i) << "\t" << kMidName(i) << endl;
00050     }
00051   string  s;
00052   cout << endl << "Select a device for kmidi to use.." << endl;
00053   cin >> s;
00054   return atoi(s.c_str());
00055 }
00056 
00057 KMIDI::KMIDI()
00058 {
00059   cerr << "libkmid initialisation..." << endl;
00060   if(KMidSimpleAPI::kMidInit())
00061     {
00062     cerr << "failed. Falling back..." << endl;
00063     throw 0;
00064     }
00065 
00066   // This is probably not right for anyone but me
00067 
00068   int devnum;
00069   bool  changed=false;
00070 
00071   config->value("config/audio/midi/kmidi/device",devnum,-2);
00072   if(devnum==-1)
00073     {
00074     // kmidi is disabled
00075     throw 0;
00076     }
00077   if(devnum==-2)
00078     {
00079     devnum=kmidi_device_selection();
00080     changed=true;
00081     if(devnum==-1)
00082       {
00083       // User disabled kmidi
00084       devnum=-2;
00085       config->set("config/audio/midi/kmidi/device",devnum,true);
00086       throw 0;
00087       }
00088     }
00089   kMidSetDevice(devnum);
00090   if(changed)
00091     {
00092     config->set("config/audio/midi/kmidi/device",devnum,true);
00093     }
00094 }
00095 
00096 KMIDI::~KMIDI()
00097 {}
00098 
00099 
00100 void  KMIDI::start_track(XMIDIEventList *event_list,bool repeat)
00101 {
00102   const char *name = MIDITMPFILE;
00103   event_list->Write(name);
00104 
00105   if(is_playing())
00106     stop_track();
00107   repeat_=repeat;
00108 #if DEBUG
00109   cerr << "Starting midi sequence with KMIDI: " << name << endl;
00110 #endif
00111 
00112   KMidSimpleAPI::kMidLoad(name);
00113 
00114   // Something (probably SDL) traps SIGTERM which makes getting
00115   // rid of the repeating track a problem. This fixes it:
00116   signal(SIGTERM,SIG_DFL);
00117 
00118   KMidSimpleAPI::kMidPlay((repeat)?255:0);
00119 }
00120 
00121 void  KMIDI::stop_track(void)
00122 {
00123   KMidSimpleAPI::kMidStop();
00124 }
00125 
00126 bool  KMIDI::is_playing(void)
00127 {
00128   return KMidSimpleAPI::kMidIsPlaying();
00129 }
00130 
00131 const char *KMIDI::copyright(void)
00132 {
00133   return KMidSimpleAPI::kMidCopyright();
00134 }
00135   
00136 #endif // HAVE_LIBKMIDI
00137 
00138 #endif // XWIN

Generated on Mon Jul 9 14:42:41 2007 for ExultEngine by  doxygen 1.5.1