< -->

Program MusicWriter;
{$M 65520, 0, 655360}
{$G+}
Uses ProgFace, MusicShu;
var
  C : Char;
  S, Df : String;
  BgFrq, dFrq, Fru : Real;
  Sharp : Boolean;
  i, j : Word;
  Lg : Longint;
  X, Xp : Byte;
  tmpS : String;
Procedure WaitRetrace;Assembler;
asm
             mov  dx, 03DAh
@VRTL1:
             in   al, dx
             test al, 8
             jnz  @VRTL1
@VRTL2:
             in al, dx
             test   al, 8
             jne     @VRTL2
end;
Procedure Sound(Freq : Word);Assembler;
asm
	mov	bx, sp
	mov	bx, ss:[bx+4]
	mov	ax, 34DDh
	mov	dx, 12h
	cmp	dx, bx
	jnb	@1
	div	bx
	mov	bx, ax
	in	al, 61h
	test	al, 3
	jnz	@2
	or	al, 3
	out	61h, al
	mov	al, 0B6h
	out	43h, al
@2:
	mov	al, bl
	out	42h, al
	mov	al, bh
	out	42h, al
@1:
end;
{------------------------}
Procedure NoSound;Assembler;
asm
	in	al, 61h
	and	al, 0FCh
	out	61h, al
end;
Procedure SetTxPoint(X,Y,ColorTx,BkColorTx:Byte;C:Char);Assembler;
asm
        push ds
        mov ax, $B800
        mov ds, ax
        mov ah, 0
        mov bh, 0
        mov bl, byte ptr x
        cmp bx, 80
        ja  @1

        mov al, byte ptr y
        cmp ax, 25
        ja  @1

        dec ax
        mov cl, 80
        mul cl
        dec bx
        add bx, ax

        mov cl, byte ptr ColorTx
        and cl, $8F
        mov dl, BkColorTx
        mov al, dl
        and dl, $7
        shl dl, 4
        and al, $80
        or  dl, al
        or  dl, cl

        mov al, byte ptr C
        mov ah, dl
        shl bx, 1
        mov ds:[bx], ax
@1:
        pop ds
end;
var
  Timer, Timer1 : Longint;
Function GetTimer : Longint;Assembler;
asm
    mov      ah, 0
    int      $1A
    mov      ax, dx
    mov      dx, cx
end;
Procedure Inform;
begin
     ZZCursor;
     Str(i, tmpS);
     WriteLine('Количествоянот:я'+tmpS, WinAttr);
     Str(BgFrq:0:1, tmpS);
     WriteLine(';яНачальнаяячастотая:я'+tmpS+'   ', WinAttr);
end;
{------------------------}
const
   KeybTable : String[44] =      'zxcvbnm,./asdfghjkl;''qwertyuiop[]`1234567890';
   KeybShiftTable : String[44] = 'ZXCVBNM<>?ASDFGHJKL:"QWERTYUIOP{}~!@#$%^&*()';
begin
   ResetTimer;
   CursorOff;
   SetWindChar(' ');
   SaveBar(20,10, 60, 12);
   SetAttr(Red, Cyan,WinAttr);
   SetAttr(Green,Blue,WBorderAttr);
   SetAttr(Green, Blue,WinHAttr);
   WaitRetrace;
   SetWindow(20,10, 60, 12, 1, 'Введите имя файла для записи', True);
   Repeat
    S := '';
   Repeat
     ZZCursor;
     WriteLine(S + '                 ', WinAttr);
     C := ReadKey;
     if (C in ['A'..'Z']) or (C in ['a'..'z']) then S := S + C;
     if C = #0 then if ReadKey = #83 then S := '';
     if C = #8 then S[0]:= Char(Length(S)-1);
   Until (C = #27) or (C = #13);
   Until (Length(S)<=8) or (C=#27);
   if C = #27 then S := 'ю' else S := S + '.MZP';
   UndoMenu;
   SaveBar(1,20, 80, 24);
   SetWindChar('°');
   SetAttr(Green, Black,WinAttr);
   SetAttr(Black,Green,WBorderAttr);
   SetAttr(Red, Green,WinHAttr);
   WaitRetrace;
   SetWindow(1, 20, 80, 24, 2, 'Окно нажатийянаяклавиши ('+S+')', True);
   BgFrq := 27.50;
   SetNewMusTable(BgFrq, exp(ln(2)/12));
   i := 0;
   While KeyPressed do C := ReadKey;
   While not KeyPressed do;
   Timer := GetTimer;
   While KeyPressed do C := ReadKey;
   While not KeyPressed do;
   Repeat
     C := ReadKey;
     Timer1 := GetTimer-Timer;
     Timer := GetTimer;
     if (C = '-') or (C = '_') then
     begin
       BgFrq := BgFrq/2;
       SetNewMusTable(BgFrq, exp(ln(2)/12));
       Inform;
       Continue;
     end;
     if (C = '+') or (C = '=') then
     begin
       BgFrq := BgFrq*2;
       SetNewMusTable(BgFrq, exp(ln(2)/12));
       Inform;
       Continue;
     end;
     inc(i);
     Inform;
     Xp := X;
     X := 0;
     if Pos(C, KeybTable)<>0 then
       X := Pos(C, KeybTable);
     if Pos(C, KeybShiftTable)<>0 then
       X := Pos(C, KeybShiftTable)+44;
     if X <> 0 then
       MusicPhrase.MusicNotes[i].freq := ROGnots[X].freq;
     if Xp <> 0 then
     begin
      if ROGnots[Xp].Sharp then
       SetTxPoint(79-Round((ROGnots[Xp].NPos+23)*78/52), 22, Green, Black, '°')
      else
       SetTxPoint(79-Round((ROGnots[Xp].NPos+23)*78/52), 23, Green, Black, '°');
     end;
     if X <> 0 then
     begin
      if ROGnots[X].Sharp then
       SetTxPoint(79-Round((ROGnots[X].NPos+23)*78/52), 22, LightRed, Black, 'ы')
      else
       SetTxPoint(79-Round((ROGnots[X].NPos+23)*78/52), 23, LightRed, Black, 'ы');
     end;
     if C = #8 then if i > 2 then
     begin
       Timer := GetTimer;
       dFrq := (MusicPhrase.MusicNotes[i].freq-MusicPhrase.MusicNotes[i-1].freq)/10;
       dec(i);
       Inform;
       if dFrq = 0 then Continue;
{       if MusicPhrase.MusicNotes[i].freq= NNotes);
   NoSound;
   MusicPhrase.Leng := i;
   UndoMenu;
   PlayMusic(MusicPhrase);
   if S <> 'ю' then
   begin
   SetWindChar(' ');
   SaveBar(1,10, 80, 12);
   SetAttr(Red, Cyan,WinAttr);
   SetAttr(Green,Blue,WBorderAttr);
   SetAttr(Green, Blue,WinHAttr);
   WaitRetrace;
   SetWindow(1,10, 80, 12, 1, 'Введите описание файла', True);
   Repeat
    Df := '';
     Repeat
       ZZCursor;
       WriteLine(Df + '                 ', WinAttr);
       C := ReadKey;
       if (C in [#32..#255]) then Df := Df + C;
       if C = #0 then if ReadKey = #83 then Df := '';
       if C = #8 then Df[0]:= Char(Length(Df)-1);
     Until (C = #27) or (C = #13);
     Until (Length(Df)<=80) or (C=#27);
     if C = #27 then Df := 'Shyar Music Writer. Файл '+S;
     UndoMenu;
     SetMusicName(Df);
   end;
   if S = 'ю' then
    begin
     SetMusicName('Временный файл Shyar Music Writer');
     S := 'SHMWTMP.MZP';
    end;
   SaveMusicPhrase(MusicPhrase, S);
   ZZCursor;
   RestoreScreen;
   CursorOn;
end.

Назад