📄 gsmctrfr.pas
字号:
end;
end;
Records.Values['MELODY']:= S;
end;
end;
EMS.Objects.Add(EMSObj);
EMS.WriteTo(NBS as TUDHProtocol);
end
else
begin
// text msg.
end;
if NBS <> nil then
begin
NBS.SourceAddress:= NBS.DestinationAddress;
NBS.Reference:= fReference mod 256;
Inc(fReference);
if NBS is TNBS then
B:= 0
else
B:= $F5;
for I:= 1 to NBS.FragmentCount do
begin
SendSmsPhn(DA.Text, NBS.Fragments[I], DeliveryNotification.Checked, B, NBS is TUDHProtocol, True, False);
end;
end
else
begin
B:= $F0+DCS.ItemIndex;
S:= Message.Text;
F:= Pos(smBlinkOn, S) <> 0;
if F then
begin
S:= #1+S;
B:= $18; // ??? does not work, no idea how display blinking messages, other ME?
end;
SendSmsPhn(DA.Text, S, DeliveryNotification.Checked, B, False, F, F);
end;
finally
NBS.Free;
end;
finally
HideModemLog;
end;
end;
procedure TGSMCentralForm.MelodyKeyboardPaint(Sender: TObject);
var
I, J: Integer;
R: TRect;
Keyis: Boolean;
begin
with (Sender as TPaintBox).Canvas do
begin
Brush.Style:= bsSolid;
Brush.Color:= clWhite;
Pen.Width:= 1;
Pen.Style:= psClear;
for I:= 0 to MelodyScale.Items.Count-1 do
for J:= 1 to MelodyNote.Items.Count-1 do
begin
if fMelodyKeyPressed = I*256 + J then
Pen.Mode:= pmXor
else
Pen.Mode:= pmCopy;
GetKeyRect(I, J, R, Keyis);
if not Keyis then
Rectangle(R.Left, R.Top, R.Right, R.Bottom);
end;
Pen.Style:= psClear;
for I:= 0 to MelodyScale.Items.Count-1 do
for J:= 1 to MelodyNote.Items.Count-1 do
begin
if fMelodyKeyPressed = I*256 + J then
begin
Pen.Mode:= pmXor;
Brush.Color:= clSilver;
end
else
begin
Brush.Color:= clBlack;
Pen.Mode:= pmCopy;
end;
GetKeyRect(I, J, R, Keyis);
if Keyis then
Rectangle(R.Left, R.Top, R.Right, R.Bottom);
end;
end;
end;
procedure TGSMCentralForm.GetKeyRect;
var
I, N, Sc, Kpos: Integer;
begin
N:= 0;
Keyis:= False;
Kpos:= 0;
for I:= 1 to MelodyNote.Items.Count-1 do
begin
if Pos('is', MelodyNote.Items[I]) = 0 then
begin
Inc(N);
if I < aNote then
Inc(Kpos);
end
else
begin
if aNote = I then
Keyis:= True;
end;
end;
Sc:= MelodyScale.Items.Count;
R.Top:= 0;
R.Bottom:= MelodyKeyboard.Height;
R.Left:= 0;
R.Right:= MelodyKeyboard.Width div (N * Sc);
if Keyis then
begin
R.Bottom:= R.Bottom div 2;
Dec(R.Left, R.Right div 3);
end;
Inc(R.Left, Kpos * R.Right);
Inc(R.Left, N * aScale * R.Right);
if Keyis then
R.Right:= 2*R.Right div 3 + R.Left
else
R.Right:= R.Right + R.Left;
end;
procedure TGSMCentralForm.MelodyKeyboardMouseDown(Sender: TObject;
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]:= Pointer(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]:= Pointer(MelodyTempo.ItemIndex);
MelodyGrid.Cells[4, I]:= MelodyTempo.Items[MelodyTempo.ItemIndex];
MelodyGrid.Objects[5, I]:= Pointer(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]:= Pointer(NoteScale);
end
else if Instructions[I] is TSMRTTempo then
begin
with TSMRTTempo(Instructions[I]) do
MelodyGrid.Objects[4, MelodyGrid.RowCount-1]:= Pointer(BeatsPerMin);
end
else if Instructions[I] is TSMRTStyle then
begin
with TSMRTStyle(Instructions[I]) do
MelodyGrid.Objects[5, MelodyGrid.RowCount-1]:= Pointer(Value);
end
else if Instructions[I] is TSMRTNote then
begin
with TSMRTNote(Instructions[I]) do
begin
MelodyGrid.Objects[1, MelodyGrid.RowCount-1]:= Pointer(Value);
MelodyGrid.Objects[2, MelodyGrid.RowCount-1]:= Pointer(Duration);
MelodyGrid.Objects[3, MelodyGrid.RowCount-1]:= Pointer(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]:= Pointer(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
St.WriteBuffer(S[1], Length(S));
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+1]));
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:= 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:= 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:= 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:= B;
end;
Instructions.Add(TSMRTNote.Create);
with TSMRTNote(Instructions[Instructions.Count-1]) do
begin
Value:= Integer(MelodyGrid.Objects[1, I]);
Duration:= Integer(MelodyGrid.Objects[2, I]);
DurationSpecifier:= Integer(MelodyGrid.Objects[3, I]);
end;
end;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -