This section describes a very simple example program that uses MIDAS for playing music. First, the complete program source is given in both C and Delphi format, and after that the operation of the program is described line by line. To keep the program as short as possible, all error checking is omitted, and therefore it should not be used as a template for building real applications -- the other example programs included in the MIDAS distribution are more suitable for that.
Both versions of the program should be compiled as console applications in the Win32 environment. Under MS-DOS and Linux the default compiler settings are fine.
1 #include <stdio.h> 2 #include <conio.h> 3 #include "midasdll.h" 4 5 int main(void) 6 { 7 MIDASmodule module; 8 9 MIDASstartup(); 10 MIDASinit(); 11 MIDASstartBackgroundPlay(0); 12 13 module = MIDASloadModule("..\\data\\templsun.xm"); 14 MIDASplayModule(module, 0); 15 16 puts("Playing - press any key"); 17 getch(); 18 19 MIDASstopModule(module); 20 MIDASfreeModule(module); 21 22 MIDASstopBackgroundPlay(); 23 MIDASclose(); 24 25 return 0; 26 }
1 uses midasdll; 2 3 var module : MIDASmodule; 4 5 BEGIN 6 MIDASstartup; 7 MIDASinit; 8 MIDASstartBackgroundPlay(0) 9 10 module := MIDASloadModule('..\data\templsun.xm'); 11 MIDASplayModule(module, 0); 12 13 WriteLn('Playing - Press Enter'); 14 ReadLn; 15 16 MIDASstopModule(module); 17 MIDASfreeModule(module); 18 19 MIDASstopBackgroundPlay; 20 MIDASclose; 21 END.
Apart from minor syntax differences, the C and Delphi versions of the program work nearly identically. This section describes the operation of the programs line by line. The line numbers below are given in pairs: first for C, second for Delphi.