home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / demos / 57 / pascal / minimidi.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-09-18  |  9.0 KB  |  301 lines

  1. PROGRAM midi;
  2.   {+-------------------------------------------------------------------+
  3.    |                                                                   |
  4.    |        ***                  MINI MIDI ST                 ***      |
  5.    |               a computerized sequencer by Tim Trzepacz            |
  6.    |                                                                   |
  7.    +-------------------------------------------------------------------+}
  8.  
  9.   CONST
  10.        {$I gemconst.pas}
  11.   TYPE
  12.        {$I gemtype.pas}
  13.        Pointers = RECORD
  14.          a,b,c,d,e,f,g,h,i : Integer;
  15.        END;
  16.  
  17.        Midi_Data = RECORD
  18.          time : long_integer;
  19.          cmd  : Integer;
  20.        END;
  21.        Midi_Ary = ARRAY [1..5000] OF Midi_Data ;
  22.   VAR  D : Midi_Ary;
  23.        Ed : Integer;
  24.        Data : text;
  25.  
  26.       {$I gemsubs.pas}
  27.  
  28.   FUNCTION bconin( device : Integer ) : Long_Integer ;
  29.     BIOS( 2 ) ;
  30.  
  31.   FUNCTION bconstat( device : Integer ) : Boolean ;
  32.     BIOS( 1 );
  33.  
  34.   PROCEDURE bconout(device,c: Integer);
  35.     BIOS( 3 );
  36.  
  37.   FUNCTION Make_Window( title : Window_Title; Var x,y,w,h : Integer;
  38.                         style,color, t : Integer) : Integer;
  39.       BEGIN
  40.         handle:= New_Window( t , title , 0,0,0,0 );
  41.         Open_Window( handle, x , y , w , h );
  42.         Work_Rect( handle, x , y , w , h );
  43.         Set_Clip( x , y , w , h );
  44.         Paint_Style( style );
  45.         Paint_Color( color );
  46.         Paint_Rect( x , y , w , h );
  47.         Make_Window:=handle;
  48.       END;
  49.  
  50.   FUNCTION Setup_Menu(VAR P:Pointers) : Dialog_Ptr;
  51.     VAR PT : Dialog_Ptr;
  52.     BEGIN
  53.      PT:=New_Dialog(10,0,0,40,11);
  54.      P.a:= Add_DItem( PT , G_Box , None,1,1,38,4,-4 ,Black*4096|0*256|112|Red);
  55.      P.b:= Add_DItem( PT , G_Text, None,15,2,9,1,0,Black);
  56.       Set_DText( PT , P.b,'MINI MIDI',System_Font,TE_Center);
  57.      P.d:= Add_DItem( PT , G_Text, None,18,3,3,1,0,Black);
  58.       Set_DText( PT , P.d,'S T',System_Font,TE_Center);
  59.      P.f:= Add_DItem( PT , G_Text, None,2,7,13,1,0,Black * 256|Black);
  60.       Set_DText( PT , P.f,'Select Option',System_Font,TE_Center);
  61.      P.h:= Add_DItem( PT , G_Button,5,2,9,6,1,1,1);
  62.       Set_DText( PT , P.h,' EXIT ',System_Font,TE_Center);
  63.      P.i:= Add_DItem( PT , G_Button,5,9,9,6,1,1,1);
  64.       Set_DText( PT , P.i,' LOAD ',System_Font,TE_Center);
  65.      P.e:= Add_DItem( PT , G_Button,5,16,9,6,1,1,1);
  66.       Set_DText( PT , P.e,' SAVE ',System_Font,TE_Center);
  67.      P.g:= Add_DItem( PT , G_Button,5,23,9,6,1,1,1);
  68.       Set_DText( PT , P.g,' PLAY ',System_Font,TE_Center);
  69.      P.c:= Add_DItem( PT , G_Button,5,30,9,8,1,1,1);
  70.       Set_DText( PT , P.c,' RECORD ',System_Font,TE_Center);
  71.      Center_Dialog( PT );
  72.      Setup_menu:=PT;
  73.     END;
  74.  
  75.   PROCEDURE Load_File;
  76.     VAR I     : Integer;
  77.         fil  : Path_Name;
  78.         pat  : Path_Name;
  79.         dinfo : STR255;
  80.         lode  : Boolean;
  81.  
  82.     BEGIN
  83.       dinfo:='[1][Warning: Using this option will |  erase the file currently';
  84.       dinfo:=Concat(dinfo,'|  in memory.][ CANCEL | LOAD ]');
  85.       I:=Do_Alert(dinfo,1);
  86.       IF I=2 THEN
  87.         BEGIN
  88.           pat:='A:\*.MDI';
  89.           lode:=Get_In_File( pat,fil);
  90.           IF lode THEN
  91.             BEGIN
  92.               Text_Color(Red);
  93.               Text_Style(Thickened|Slanted|Outlined);
  94.               Draw_Mode(2);
  95.               Hide_Mouse;
  96.               Draw_String(285,90,'~~ Loading ~~');
  97.               Text_Color(Black);
  98.               Text_Style(0);
  99.               Show_Mouse;
  100.               Reset(Data,fil);
  101.                   Readln(data,Ed);
  102.                   FOR I:=1 To Ed DO
  103.                     BEGIN
  104.                       Readln(data,D[I].time);
  105.                       Readln(data,D[I].cmd);
  106.                     END;
  107.               Close(Data);
  108.               Paint_Color(Green);
  109.               Paint_Style(1);
  110.               Hide_Mouse;
  111.               Paint_Rect(20,20,600,150);
  112.               Show_Mouse
  113.             END
  114.         END
  115.     END;
  116.  
  117.   PROCEDURE Save_File;
  118.     VAR I     : Integer;
  119.         fil  : Path_Name;
  120.         pat  : Path_Name;
  121.         dinfo : STR255;
  122.         sav  : Boolean;
  123.  
  124.     BEGIN
  125.       pat:='A:\*.MDI';
  126.       sav:=Get_In_File( pat,fil);
  127.       IF sav THEN
  128.         BEGIN
  129.               Text_Color(Red);
  130.               Text_Style(Thickened|Slanted|Outlined);
  131.               Draw_Mode(2);
  132.               Hide_Mouse;
  133.               Draw_String(285,90,'~~ Saving ~~');
  134.               Text_Color(Black);
  135.               Text_Style(0);
  136.               Show_Mouse;
  137.           Rewrite(Data,fil);
  138.               Writeln(data,Ed);
  139.               FOR I:=1 To Ed DO
  140.                 BEGIN
  141.                   Writeln(data,D[I].time);
  142.                   Writeln(data,D[I].cmd);
  143.                 END;
  144.           Close(Data);
  145.               Paint_Color(Green);
  146.               Paint_Style(1);
  147.               Hide_Mouse;
  148.               Paint_Rect(20,20,600,150);
  149.               Show_Mouse
  150.         END
  151.     END;
  152.  
  153.   PROCEDURE Clear_Midi_Buffer;
  154.     Var Dummy:Long_Integer;
  155.     BEGIN
  156.       While Bconstat(3)=True DO
  157.         BEGIN
  158.           dummy:=bconin(3);
  159.         END;
  160.     END;
  161.  
  162.   PROCEDURE Play_Music ;
  163.     VAR I , du : Integer;
  164.         dinfo : STR255;
  165.         At    : Long_Integer;
  166.         Test  : boolean;
  167.         dummy : Long_Integer;
  168.     BEGIN
  169.       dinfo:='[0][Play Recording:|      Press the RETURN key';
  170.       dinfo:=Concat(dinfo,'|      to play the recording,');
  171.       dinfo:=Concat(dinfo,'|      or click on cancel to');
  172.       dinfo:=Concat(dinfo,'|      abort.][ Cancel | Play ]');
  173.       I:=Do_Alert(dinfo,2);
  174.       IF I=2 THEN
  175.         BEGIN
  176.           Text_Color(Red);
  177.           Text_Style(Thickened|Slanted|Outlined);
  178.           Draw_Mode(2);
  179.           Hide_Mouse;
  180.           Clear_Midi_Buffer;
  181.           Draw_String(285,90,'Playing');
  182.           Text_Color(Black);
  183.           Text_Style(0);
  184.           Draw_String(200,99,'Press any key to stop playing.');
  185.           Show_Mouse;
  186.           AT:=0;
  187.           I:=1;
  188.           REPEAT
  189.             AT:=AT+1;
  190.             For du:=1 to 5 DO
  191.               BEGIN
  192.                 ;
  193.               END;
  194.             IF D[I].time=AT THEN
  195.               BEGIN
  196.                 bconout(3,D[I].cmd);
  197.                 I:=I+1;
  198.               END;
  199.             Test:=bconstat(2);
  200.           UNTIL Test or (I=Ed);
  201.           If Test THEN dummy:=bconin(2);
  202.           Draw_Mode(1);
  203.           Paint_Color(Green);
  204.           Paint_Style(1);
  205.           Hide_Mouse;
  206.           Paint_Rect(20,20,600,150);
  207.           Show_Mouse
  208.         END
  209.     END;
  210.  
  211.   FUNCTION Record_Music : Integer;
  212.     VAR I     : Integer;
  213.         dinfo : STR255;
  214.         At    : Long_Integer;
  215.         dummy : Long_Integer;
  216.     BEGIN
  217.       dinfo:='[0][Record Music:|      Press the RETURN key';
  218.       dinfo:=Concat(dinfo,'|      to start recording, or');
  219.       dinfo:=Concat(dinfo,'|      click on cancel to abort.]');
  220.       dinfo:=Concat(dinfo,'[ Cancel | Record ]');
  221.       I:=Do_Alert(dinfo,2);
  222.       IF I=2 THEN
  223.         BEGIN
  224.           Text_Color(Black);
  225.           Text_Style(Thickened|Slanted|Outlined);
  226.           Draw_Mode(2);
  227.           Hide_Mouse;
  228.           Clear_Midi_Buffer;
  229.           Draw_String(275,90,'Recording');
  230.           Text_Style(0);
  231.           Draw_String(192,99,'Press any key to stop recording.');
  232.           Show_Mouse;
  233.           AT:=0;
  234.           I:=1;
  235.           REPEAT
  236.             AT:=AT+1;
  237.             IF bconstat(3) THEN
  238.               BEGIN
  239.                 dummy:=bconin(3);
  240.                 D[I].time:=AT;
  241.                 D[I].cmd :=int(dummy);
  242.                 I:=I+1
  243.               END;
  244.           UNTIL bconstat(2);
  245.           Record_Music:=I;
  246.           dummy:=bconin(2);
  247.           Draw_Mode(1);
  248.           Paint_Color(Green);
  249.           Paint_Style(1);
  250.           Hide_Mouse;
  251.           Paint_Rect(20,20,600,150);
  252.           Show_Mouse
  253.         END
  254.     END;
  255.  
  256.   PROCEDURE Bye ;
  257.     VAR dinfo : STR255;
  258.         dummy : integer;
  259.     BEGIN
  260.                 dinfo:='[0][  Mini  Midi  ST';
  261.       dinfo:=concat(dinfo,'|   version  1.0');
  262.       dinfo:=concat(dinfo,'|------------------');
  263.       dinfo:=concat(dinfo,'| By  Tim Trzepacz');
  264.       dinfo:=concat(dinfo,'| and  Darren Moon');
  265.       dinfo:=concat(dinfo,'|------------------');
  266.       dinfo:=Concat(dinfo,'|Wireless Computing');
  267.       dinfo:=concat(dinfo,'| Services 8/19/86]');
  268.       dinfo:=Concat(dinfo,'[        Bye       ]');
  269.       dummy:=Do_Alert(dinfo,1);
  270.     END;
  271.  
  272. PROCEDURE Menu;
  273.     VAR  PT  : Dialog_Ptr;
  274.          Op  : Integer;
  275.          P   : Pointers;
  276.     BEGIN
  277.       REPEAT
  278.         PT:=Setup_Menu(P);
  279.         Op:= Do_Dialog( PT , 0);
  280.         End_Dialog( PT );
  281.         WITH P DO
  282.           BEGIN
  283.             IF Op=I THEN  Load_File
  284.               ELSE IF Op=E THEN Save_File
  285.                 ELSE IF Op=G THEN Play_Music
  286.                  ELSE IF OP=C THEN Ed:=Record_Music
  287.           END;
  288.       UNTIL (Op=P.h);
  289.     END;
  290.  
  291.   BEGIN
  292.     IF Init_GEM >=0 THEN
  293.       BEGIN
  294.         Init_Mouse;
  295.         Ed:=2;
  296.         Menu;
  297.         Bye;
  298.         Exit_Gem
  299.       END
  300.   END.
  301. əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə