amiga_midi.cc

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2001 Ruediger Hanke
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 #if defined(__MORPHOS__) || defined( AMIGA )
00024 
00025 #define NO_PPCINLINE_STDARG
00026 #include <proto/exec.h>
00027 
00028 // "Remove" has been defined as a macro in ppcinline/exec.h and it will clash with a
00029 // definition in xmidi.h so I better undefine this here.
00030 #undef Remove
00031 #include "amiga_midi.h"
00032 #include "Configuration.h"
00033 extern  Configuration *config;
00034 
00035 AmigaMIDI::AmigaMIDI()
00036 {
00037   int amUnit = 0;
00038 
00039   FileOpen = false;
00040   amMsgPort = NULL;
00041   amMidiRequest = NULL;
00042 
00043   config->value( "config/audio/midi/unit", amUnit, 0 );
00044 
00045   /* Open amidi.device */
00046   amMsgPort = CreateMsgPort();
00047   if( amMsgPort )
00048   {
00049     amMidiRequest = (struct IOMidiRequest *)CreateIORequest( amMsgPort, sizeof( struct IOMidiRequest ) );
00050     if( amMidiRequest )
00051     {
00052       amMidiRequest->amr_Version = 1;
00053       if( !OpenDevice( "amidi.device", amUnit, (struct IORequest *)amMidiRequest, 0 ) )
00054         return;
00055       DeleteIORequest( amMidiRequest );
00056       amMidiRequest = NULL;
00057     }
00058     DeleteMsgPort( amMsgPort );
00059     amMsgPort = NULL;
00060   }
00061 }
00062 
00063 AmigaMIDI::~AmigaMIDI(void)
00064 {
00065   stop_track();
00066   if( amMidiRequest )
00067   {
00068     CloseDevice( (struct IORequest *)amMidiRequest );
00069     DeleteIORequest( amMidiRequest );
00070     DeleteMsgPort( amMsgPort );
00071   }
00072 }
00073 
00074 void AmigaMIDI::stop_track(void)
00075 {
00076   if( FileOpen )
00077   {
00078     if( amMidiRequest->amr_Std.io_Command == CMD_WRITE )
00079     {
00080       AbortIO( (struct IORequest *)amMidiRequest );
00081       WaitIO( (struct IORequest *)amMidiRequest );
00082     }
00083 
00084     FileOpen = false;
00085   }
00086 }
00087 
00088 bool AmigaMIDI::is_playing(void)
00089 {
00090   bool open;
00091 
00092   open = FileOpen && amMidiRequest->amr_Std.io_Command == CMD_WRITE && CheckIO( (struct IORequest *)amMidiRequest ) == NULL;
00093 
00094   return open;
00095 }
00096 
00097 
00098 void AmigaMIDI::start_track(XMIDIEventList *event_list,bool repeat)
00099 {
00100   if( amMidiRequest )
00101   {
00102     const static char *name = "T:u7midi";
00103     event_list->Write(name);
00104     
00105     stop_track();
00106 
00107     FileOpen = true;
00108     amMidiRequest->amr_Std.io_Command = CMD_WRITE;
00109     amMidiRequest->amr_Std.io_Data = (APTR)name;
00110     amMidiRequest->amr_Std.io_Length = 0;
00111     amMidiRequest->amr_Loop = repeat ? -1 : 0;
00112     SendIO( (struct IORequest *)amMidiRequest );
00113   }
00114 }
00115 
00116 const char *AmigaMIDI::copyright(void)
00117 {
00118 #ifdef __MORPHOS__
00119   return "MorphOS AMIDI MIDI player";
00120 #else
00121   return "AmigaOS AMIDI MIDI player";
00122 #endif
00123 }
00124 
00125 #endif
00126 

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