/*************************************************************************** Set your editor's TAB width to 3. This is an example C application using the dissidents' SAMP library. It uses the dissidents' requester.library to allow the user to choose a SAMP file to load. It then loads the SAMP file, and plays back all of the midi notes (0 to 127) of the PlayMap using the audio device. This example is in the public domain, and may be used by any other program. Written by Jim Fiore and Jeff Glatt, dissidents ****************************************************************************/ #include "exec/types.h" #include "exec/memory.h" #include "hardware/custom.h" #include "hardware/dmabits.h" #include "libraries/dos.h" #include "libraries/dosextens.h" #include "devices/audio.h" #include "functions.h" #include "exec/tasks.h" #include "intuition/intuition.h" #include "intuition/intuitionbase.h" #include "graphics/gfx.h" #include "graphics/gfxbase.h" #include "graphics/rastport.h" #include "graphics/gfxmacros.h" #include "graphics/view.h" #include "graphics/text.h" /*=============== Include files for dissidents' custom libraries ===========*/ #include "FileIO.h" #include "SAMP.h" /*=================== For audio.device playback of wave ==================*/ struct IOAudio ioaudio = {0}, ioaudio2 = {0}; struct MsgPort *audPort = 0L; UBYTE audio_gub = 0; UBYTE anychan[4] = {1,2,4,8}; /*================== For dissidents requester.library =================*/ struct RequesterBase *RequesterBase = 0L; struct FileIO *fileio_sup = 0L; UBYTE fileio_filename[260]; /*==================== For dissidents samp.library =====================*/ extern LONG SAMPError; /* This comes from SAMPInterface.asm */ struct SAMPBase *SAMPBase = 0L; struct SAMPInfo *libSAMPinfo = 0L; #define playCHANS 4 UBYTE play_map[128*playCHANS]; /* let NumOfChans = 4 */ struct TransposeNode *T_List = 0L; /* Declare 32 SampleHeader64 structs for loading up to 32 waves in a SAMP */ #define MAXSAMPLES 32 #define NAMESIZE 16 struct SampleHeader64 samp_head[MAXSAMPLES]; UBYTE nameBuffers[NAMESIZE*MAXSAMPLES]; /* for the wave names */ /*====================== The C Application begins here ==================*/ VOID open_all(), exit_all(); main() { ULONG totalWaves, err, p; LONG transposeAmount; USHORT waveNum, i; UBYTE *address, b; struct TransposeNode *transL, *transL2; /* Open libs, initialize audio dev and structures, get FileIO struct */ open_all(); /* choose the SAMP file to load via the requester.library */ address = DoFileIOWindow(fileio_sup, 0L); if( address == fileio_filename ) { /* Open the file and determine if it is a SAMP */ if( !(libSAMPinfo = OpenSampRead( fileio_filename, 0L )) ) { address = SAMPErrorMsg( SAMPError ); puts( address ); exit_all(); } libSAMPinfo->MaxChars = NAMESIZE; /* Load up to 32 waves starting with the first wave in the SAMP (0) We'll load these into our samp_head and nameBuffers starting with the first member of each array. */ if( !(totalWaves = ReadWaves( 0L, 32L , &nameBuffers[0], &samp_head[0] )) ) { /* We didn't load ANY waves! Must be an empty SAMP. */ CloseSamp(); address = SAMPErrorMsg( SAMPError ); puts( address ); exit_all(); } /* This zeros out our playMap and transfers the loaded playMap to our passed playMap. It adjusts for difference in numOfChans between our program's playMap (4 chans) and the loaded playMap (0 to 4 chans). Also, it ensures that only those wave numbers that we loaded appear in our play_map. We pass an offset of 0 because we loaded from the first SampleHeader64 in our samp_head array. */ LoadPlaymap(totalWaves, 4L, 0L, 0L, &play_map[0]); for(i=0; iNext; FreeMem( transL, transL->TSize ); transL = transL2; } } /* Now close down and get some food */ exit_all(); } } /********** end of main() ********/ /*---------- Opens audio dev, audio port, SAMP and FileIO libs ---------*/ VOID open_all() { ULONG err,x,total; /* Open the requester library and allocate/setup a FileIO structure */ if( !(RequesterBase=(struct RequesterBase *)OpenLibrary("requester.library", 1L)) ) { puts("need requester.library, Not ARP\n"); exit_all(); } if( !(fileio_sup = GetFileIO()) ) { puts("Can't get FileIO support\n"); exit_all(); } fileio_sup->X = 6; fileio_sup->Y = 11; fileio_sup->DrawMode = JAM2; fileio_sup->PenA = 0; fileio_sup->PenB = 1; fileio_sup->Buffer = (UBYTE *)fileio_filename; /* Open the SAMP reader/writer library */ if( !(SAMPBase=(struct SAMPBase *)OpenLibrary("samp.library", 0L)) ) { puts("need samp.library you knuckle-head\n"); exit_all(); } /* Open audio.device and allocate a channel */ if( !(audPort = CreatePort( "SAMP_Port", 0 )) ) { puts("no audio port"); exit_all(); } ioaudio.ioa_Request.io_Message.mn_ReplyPort = audPort; ioaudio.ioa_Request.io_Command = ADCMD_ALLOCATE; ioaudio.ioa_Data = (UBYTE *)anychan; ioaudio.ioa_Length = 4; ioaudio.ioa_Request.io_Flags = ADIOF_NOWAIT | IOF_QUICK; if( OpenDevice("audio.device", 0, &ioaudio, 0 ) ) { puts("audio device open error\n"); exit_all(); } if( !(ioaudio.ioa_Request.io_Flags & IOF_QUICK ) ) GetMsg( audPort ); audio_gub = 1; ioaudio2 = ioaudio; /* initialize the AudioIO for the looping portion */ } /*-----------closes audio dev, audio port, FileIO and SAMP libs---------*/ VOID exit_all() { if( audio_gub ) CloseDevice( &ioaudio ); if( audPort ) DeletePort( audPort ); if( fileio_sup ) ReleaseFileIO( fileio_sup ); if( RequesterBase ) CloseLibrary( RequesterBase ); if( SAMPBase ) CloseLibrary( SAMPBase ); exit( FALSE ); }