⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gsmctrfr.pas

📁 boomerang library 5.11 internet ed
💻 PAS
📖 第 1 页 / 共 4 页
字号:
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  I, J: Integer;
  fMelodyKeyRect: TRect;
  F, Keyis: Boolean;
begin
  for F:= True downto False do
    for I:= 0 to MelodyScale.Items.Count-1 do
      for J:= 1 to MelodyNote.Items.Count-1 do
      begin
        GetKeyRect(I, J, fMelodyKeyRect, Keyis);
        if (Keyis = F) and (fMelodyKeyRect.Left<= X) and (fMelodyKeyRect.Right >X) and (fMelodyKeyRect.Top <= Y) and (fMelodyKeyRect.Bottom >Y) then
        begin
          fMelodyKeyPressed:= I * 256 + J;
          fMelodyKeyPressTick:= GetTickCount;
          MelodyScale.ItemIndex:= I;
          MelodyNote.ItemIndex:= J;
          MelodyKeyboard.Repaint;
          Exit;
        end;
      end;
end;

procedure TGSMCentralForm.MelodyKeyboardMouseUp(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
  T: Integer;
  I: Byte;
begin
  fMelodyKeyPressed:= 0;
  MelodyKeyboard.Repaint;
  T:= Integer(GetTickCount) - fMelodyKeyPressTick;
  if T < 50 then I:= 5
  else if T < 100 then I:= 4
  else if T < 200 then I:= 3
  else if T < 300 then I:= 2
  else if T < 500 then I:= 1
  else I:= 0;
  MelodyDuration.ItemIndex:= I;
  Button5.Click;
end;

procedure TGSMCentralForm.MelodySetFromGrid;
var
  I, J: Integer;
begin
  if MelodyGrid.RowCount <= 2 then
    J:= 0
  else
    J:= MelodyGrid.Row;
  for I:= 0 to MelodyGrid.ColCount-1 do
  begin
    fMelodyArray[I].ItemIndex:= Integer(MelodyGrid.Objects[I, J]);
  end;
end;

procedure TGSMCentralForm.Button5Click(Sender: TObject);
var
  I, J: Integer;
begin
  if MelodyInsert.Checked or (MelodyGrid.Row = MelodyGrid.RowCount-1) then
  begin
    MelodyGrid.RowCount:= MelodyGrid.RowCount+1;
    for I:= MelodyGrid.RowCount-2 downto MelodyGrid.Row do
      for J:= 0 to MelodyGrid.ColCount-1 do
      begin
        MelodyGrid.Cells[J, I+1]:= MelodyGrid.Cells[J, I];
        MelodyGrid.Objects[J, I+1]:= MelodyGrid.Objects[J, I];
      end;
  end;
  for I:= 0 to MelodyGrid.ColCount-1 do
  begin
    MelodyGrid.Objects[I, MelodyGrid.Row]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(fMelodyArray[I].ItemIndex);
    MelodyGrid.Cells[I, MelodyGrid.Row]:= fMelodyArray[I].Items[fMelodyArray[I].ItemIndex];
  end;
  MelodyGrid.Row:= MelodyGrid.Row+1;
  if SMSKind.ItemIndex = 2 then
    for I:= 1 to MelodyGrid.RowCount-2 do            // there is global settings of tempo and style in EME melody
    begin
      MelodyGrid.Objects[4, I]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(MelodyTempo.ItemIndex);
      MelodyGrid.Cells[4, I]:= MelodyTempo.Items[MelodyTempo.ItemIndex];
      MelodyGrid.Objects[5, I]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(MelodyStyle.ItemIndex);
      MelodyGrid.Cells[5, I]:= MelodyStyle.Items[MelodyStyle.ItemIndex];
    end;
end;

procedure TGSMCentralForm.Button6Click(Sender: TObject);
var
  I, J: Integer;
begin
  if (MelodyGrid.RowCount > 2) and (MelodyGrid.Row < MelodyGrid.RowCount-1) then
  begin
    for I:= MelodyGrid.Row to MelodyGrid.RowCount-1 do
      for J:= 0 to MelodyGrid.ColCount-1 do
      begin
        MelodyGrid.Cells[J, I]:= MelodyGrid.Cells[J, I+1];
        MelodyGrid.Objects[J, I]:= MelodyGrid.Objects[J, I+1];
      end;
    MelodyGrid.RowCount:= MelodyGrid.RowCount-1;
    if (MelodyGrid.Row = MelodyGrid.RowCount-1) and (MelodyGrid.RowCount > 2) then
      MelodyGrid.Row:= MelodyGrid.Row-1;
  end;
end;

procedure TGSMCentralForm.MelodyGridDblClick(Sender: TObject);
begin
  MelodySetFromGrid;
end;

procedure TGSMCentralForm.Button1Click(Sender: TObject);
var
  Sg: TStrings;
  I, J, N: Integer;
  SM: TSMRingingTone;
begin
  if OpenMelodyDialog.Execute then
  begin
    Sg:= TStringList.Create;
    try
      Sg.LoadFromFile(OpenMelodyDialog.FileName);
      N:= StrToIntDef(Sg.Values['Count'], 0);
      if (N = 0) and (Sg.Count = 1) then
        begin   // try as RTTTL
          SM:= TSMRingingTone.Create;
          try
            SM.RTTTL:= Sg[0];
            MelodyGrid.RowCount:= 2;
            for J:= 0 to MelodyGrid.ColCount-1 do
              MelodyGrid.Objects[J, MelodyGrid.RowCount-1]:= MelodyGrid.Objects[J, MelodyGrid.RowCount-2];
            if SM.Commands.Count > 0 then
              with TSMRTCommand(SM.Commands[0]) do
              begin
                if Parts.Count > 1 then
                  if Parts[0] is TSMRTRingingTone then
                  begin
                    if Parts[1] is TSMRTBasicSong then
                      MelodyName.Text:= TSMRTBasicSong(Parts[1]).Title
                    else if Parts[1] is TSMRTTemporarySong then
                      MelodyName.Text:= ''
                    else
                      Exit;
                    with TSMRTTemporarySong(Parts[1]) do
                      if Patterns.Count > 0 then
                      begin
                        with TSMRTPattern(TSMRTTemporarySong(Parts[1]).Patterns[0]) do
                        begin
                          for I:= 0 to Instructions.Count-1 do
                          begin
                            if Instructions[I] is TSMRTScale then
                              begin
                                with TSMRTScale(Instructions[I]) do
                                  MelodyGrid.Objects[0, MelodyGrid.RowCount-1]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(Integer(NoteScale));
                              end
                            else if Instructions[I] is TSMRTTempo then
                              begin
                                with TSMRTTempo(Instructions[I]) do
                                  MelodyGrid.Objects[4, MelodyGrid.RowCount-1]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(Integer(BeatsPerMin));
                              end
                            else if Instructions[I] is TSMRTStyle then
                              begin
                                with TSMRTStyle(Instructions[I]) do
                                  MelodyGrid.Objects[5, MelodyGrid.RowCount-1]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(Integer(Value));
                              end
                            else if Instructions[I] is TSMRTNote then
                              begin
                                with TSMRTNote(Instructions[I]) do
                                begin
                                  MelodyGrid.Objects[1, MelodyGrid.RowCount-1]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(Integer(Value));
                                  MelodyGrid.Objects[2, MelodyGrid.RowCount-1]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(Integer(Duration));
                                  MelodyGrid.Objects[3, MelodyGrid.RowCount-1]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(Integer(DurationSpecifier));
                                end;
                                for J:= 0 to MelodyGrid.ColCount-1 do
                                  MelodyGrid.Cells[J, MelodyGrid.RowCount-1]:= fMelodyArray[J].Items[Integer(MelodyGrid.Objects[J, MelodyGrid.RowCount-1])];
                                MelodyGrid.RowCount:= MelodyGrid.RowCount+1;
                                for J:= 0 to MelodyGrid.ColCount-1 do
                                  MelodyGrid.Objects[J, MelodyGrid.RowCount-1]:= MelodyGrid.Objects[J, MelodyGrid.RowCount-2];
                              end;
                          end;
                        end;
                      end;
                  end;
              end;

          finally
            SM.Free;
          end;
        end
      else
        begin   // plain text
          MelodyName.Text:= Sg.Values['Name'];
          MelodyGrid.RowCount:= N+2;
          for I:= 0 to N-1 do
          begin
            for J:= 0 to MelodyGrid.ColCount-1 do
            begin
              MelodyGrid.Objects[J, I+1]:= {$IFDEF CLR}TObject{$ELSE}Pointer{$ENDIF}(StrToIntDef(Sg.Values[Format('%d.%d', [I, J])], 0));
              MelodyGrid.Cells[J, I+1]:= fMelodyArray[J].Items[Integer(MelodyGrid.Objects[J, I+1])];
            end;
          end;
        end;
      for J:= 0 to MelodyGrid.ColCount-1 do
      begin
        MelodyGrid.Objects[J, MelodyGrid.RowCount-1]:= nil;
        MelodyGrid.Cells[J, MelodyGrid.RowCount-1]:= '';
      end;
      MelodyGrid.Row:= 1;
    finally
      Sg.Free;
    end;
    SaveMelodyDialog.FileName:= OpenMelodyDialog.FileName;
  end;
end;

procedure TGSMCentralForm.Button4Click(Sender: TObject);
var
  Sg: TStrings;
  I, J: Integer;
  St: TFileStream;
  S: string;
  SM: TSMRingingTone;
begin
  if SaveMelodyDialog.Execute then
  begin
    if Pos('RTT', UpperCase(ExtractFileExt(SaveMelodyDialog.FileName))) <> 0 then
      begin
        SM:= TSMRingingTone.Create;
        try
          SMRingingToneFromGrid(SM);
          S:= SM.RTTTL;
          if S <> '' then
          begin
            St:= TFileStream.Create(SaveMelodyDialog.FileName, fmCreate);
            try
              StringToStream(S, St);
            finally
              St.Free;
            end;
          end;
        finally
          SM.Free;
        end;
      end
    else
      begin
        Sg:= TStringList.Create;
        try
          Sg.Values['Name']:= MelodyName.Text;
          Sg.Values['Count']:= IntToStr(MelodyGrid.RowCount-2);

          for I:= 1 to MelodyGrid.RowCount-2 do
          begin
            for J:= 0 to MelodyGrid.ColCount-1 do
            begin
              Sg.Values[Format('%d.%d', [I-1, J])]:= IntToStr(Integer(MelodyGrid.Objects[J, I]));
            end;
          end;
          Sg.SaveToFile(SaveMelodyDialog.FileName);
        finally
          Sg.Free;
        end;
      end;
  end;

end;

procedure TGSMCentralForm.SMRingingToneFromGrid(SM: TSMRingingTone);
var
  I, B: Integer;
begin
  SM.Commands.Add(TSMRTCommand.Create);
  with TSMRTCommand(SM.Commands[0]) do
  begin
    Parts.Add(TSMRTRingingTone.Create);
    if Trim(MelodyName.Text) = '' then
      Parts.Add(TSMRTTemporarySong.Create)
    else
      begin
        Parts.Add(TSMRTBasicSong.Create);
        TSMRTBasicSong(Parts[1]).Title:= MelodyName.Text;
      end;
    TSMRTTemporarySong(Parts[1]).Patterns.Add(TSMRTPattern.Create);
    with TSMRTPattern(TSMRTTemporarySong(Parts[1]).Patterns[0]) do
    begin
      for I:= 1 to MelodyGrid.RowCount-2 do
      begin
        B:= Integer(MelodyGrid.Objects[0, I]);  // note: in row 0 are defaults
        if B <> Integer(MelodyGrid.Objects[0, I-1]) then
        begin
          Instructions.Add(TSMRTScale.Create);
          TSMRTScale(Instructions[Instructions.Count-1]).NoteScale:= I2B(B);
        end;
        B:= Integer(MelodyGrid.Objects[4, I]);  // note: in row 0 are defaults
        if B <> Integer(MelodyGrid.Objects[4, I-1]) then
        begin
          Instructions.Add(TSMRTTempo.Create);
          TSMRTTempo(Instructions[Instructions.Count-1]).BeatsPerMin:= I2B(B);
        end;
        B:= Integer(MelodyGrid.Objects[6, I]);  // note: in row 0 are defaults
        if B <> Integer(MelodyGrid.Objects[6, I-1]) then
        begin
          Instructions.Add(TSMRTVolume.Create);
          TSMRTVolume(Instructions[Instructions.Count-1]).Value:= I2B(B);
        end;
        B:= Integer(MelodyGrid.Objects[5, I]);  // note: in row 0 are defaults
        if B <> Integer(MelodyGrid.Objects[5, I-1]) then
        begin
          Instructions.Add(TSMRTStyle.Create);
          TSMRTStyle(Instructions[Instructions.Count-1]).Value:= I2B(B);
        end;
        Instructions.Add(TSMRTNote.Create);
        with TSMRTNote(Instructions[Instructions.Count-1]) do
        begin
          Value:= I2B(Integer(MelodyGrid.Objects[1, I]));
          Duration:= I2B(Integer(MelodyGrid.Objects[2, I]));
          DurationSpecifier:= I2B(Integer(MelodyGrid.Objects[3, I]));
        end;
      end;
    end;
  end;
end;

procedure TGSMCentralForm.Button7Click(Sender: TObject);
var
  D: TOpenDialog;
begin
  case SMSKind2.ItemIndex of
    0:
      begin
        D:= OpenPictureDialog;
      end;
    1:
      begin
        D:= OpenSEOMidiDialog;
      end;
    else
      D:= nil;
  end;
  D.FileName:= SEOFileName.Text;
  if D.Execute then
    SEOFileName.Text:= D.FileName;
  AdjustSEO;
end;

procedure TGSMCentralForm.AdjustSEO;
begin
  SEOName.Text:= ExtractFileName(SEOFileName.Text);
  case SMSKind2.ItemIndex of
    0:
      begin
        SEOMidi.Close;
        fSEOPictureFileName:= SEOFileName.Text;
        try
          SEOPicture.Picture.Assign(nil);
          if SEOFileName.Text <> '' then
            SEOPicture.Picture.LoadFromFile(SEOFileName.Text);
        except
        end;
      end;
    1:
      begin
        SEOMidi.Close;
        SEOMidi.FileName:= SEOFileName.Text;
        try
          if SEOMidi.FileName <> '' then
            SEOMidi.Open;
        except
        end;
      end;
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -