@@ -5,30 +5,13 @@ unit ClipboardUtils; |
| 5 |
interface |
5 |
interface |
| 6 |
|
6 |
|
| 7 |
uses |
7 |
uses |
| 8 |
Classes, SysUtils, Constants, Clipbrd, HugeDatatypes; |
8 |
Classes, SysUtils, Constants, Clipbrd, HugeDatatypes, Utils; |
| 9 |
|
9 |
|
| 10 |
{type |
|
|
| 11 |
TModplugClipboardCell = packed record |
|
|
| 12 |
Note: array[0..2] of Char; |
|
|
| 13 |
Instrument: array[0..1] of Char; |
|
|
| 14 |
Volume: array[0..2] of Char; |
|
|
| 15 |
EffectCode: Char; |
|
|
| 16 |
EffectParams: array[0..1] of Char; |
|
|
| 17 |
end;} |
|
|
| 18 |
|
|
|
| 19 |
// function ModplugToHuge(MPCell: TModplugClipboardCell): TCell; |
|
|
| 20 |
function GetPastedCells: TSelection; |
10 |
function GetPastedCells: TSelection; |
|
|
11 |
procedure CopyCells(Selection: TSelection); |
| 21 |
|
12 |
|
| 22 |
implementation |
13 |
implementation |
| 23 |
|
14 |
|
| 24 |
{function ModplugToHuge(MPCell: TModplugClipboardCell): TCell; |
|
|
| 25 |
begin |
|
|
| 26 |
Result.Note := NoteToCodeMap.KeyData[String(MPCell.Note)]; |
|
|
| 27 |
Result.Instrument := StrToInt(String(MPCell.Instrument)); |
|
|
| 28 |
Result.EffectCode := StrToInt(String('0x'+MPCell.EffectCode)); |
|
|
| 29 |
Result.EffectParams.Value := StrToInt(String('0x'+MPCell.EffectParams)); |
|
|
| 30 |
end;} |
|
|
| 31 |
|
|
|
| 32 |
function ParseCell(Cell: String): TCell; |
15 |
function ParseCell(Cell: String): TCell; |
| 33 |
var |
16 |
var |
| 34 |
Note, Instr, EffectCode, EffectParam1, EffectParam2: String; |
17 |
Note, Instr, EffectCode, EffectParam1, EffectParam2: String; |
@@ -52,27 +35,28 @@ begin |
| 52 |
if TryStrToInt('x'+EffectParam1, Temp) then |
35 |
if TryStrToInt('x'+EffectParam1, Temp) then |
| 53 |
Result.EffectParams.Param1 := Temp |
36 |
Result.EffectParams.Param1 := Temp |
| 54 |
else |
37 |
else |
| 55 |
Result.EffectParams.Param1 := 0; |
38 |
Result.EffectParams.Value := 0; |
| 56 |
|
39 |
|
| 57 |
if TryStrToInt('x'+EffectParam2, Temp) then |
40 |
if TryStrToInt('x'+EffectParam2, Temp) then |
| 58 |
Result.EffectParams.Param2 := Temp |
41 |
Result.EffectParams.Param2 := Temp |
| 59 |
else |
42 |
else |
| 60 |
Result.EffectParams.Param2 := 0; |
43 |
Result.EffectParams.Value := 0; |
| 61 |
end; |
44 |
end; |
| 62 |
|
45 |
|
| 63 |
function GetPastedCells: TSelection; |
46 |
function GetPastedCells: TSelection; |
| 64 |
var |
47 |
var |
| 65 |
SL: TStringList; |
48 |
SL: TStringList; |
| 66 |
StringCells: TStringArray; |
49 |
StringCells: TStringArray; |
| 67 |
Row, Cell, S: String; |
50 |
Row: String; |
| 68 |
I, J: Integer; |
51 |
I, J: Integer; |
| 69 |
begin |
52 |
begin |
| 70 |
SL := TStringList.Create; |
53 |
SL := TStringList.Create; |
| 71 |
try |
54 |
try |
| 72 |
SL.Text := Clipboard.AsText; |
55 |
SL.Text := Clipboard.AsText; |
| 73 |
|
56 |
|
| 74 |
// First line is the header, last is a blank line |
57 |
// Delete lines until we reach the note data |
| 75 |
SL.Delete(0); |
58 |
while not SL.Strings[0].StartsWith('|') do |
|
|
59 |
SL.Delete(0); |
| 76 |
SetLength(Result, SL.Count); |
60 |
SetLength(Result, SL.Count); |
| 77 |
|
61 |
|
| 78 |
I := 0; |
62 |
I := 0; |
@@ -89,5 +73,38 @@ begin |
| 89 |
end; |
73 |
end; |
| 90 |
end; |
74 |
end; |
| 91 |
|
75 |
|
|
|
76 |
function SerializeCell(Cell: TCell): String; |
|
|
77 |
begin |
|
|
78 |
Result := '|'; |
|
|
79 |
|
|
|
80 |
Result += NoteCodeToString(Cell.Note); |
|
|
81 |
Result += FormatFloat('00', Cell.Instrument); |
|
|
82 |
Result += '...'; // volume |
|
|
83 |
Result += EffectCodeToStr(Cell.EffectCode, Cell.EffectParams); |
|
|
84 |
end; |
|
|
85 |
|
|
|
86 |
procedure CopyCells(Selection: TSelection); |
|
|
87 |
var |
|
|
88 |
C, R: Integer; |
|
|
89 |
S: String; |
|
|
90 |
SL: TStringList; |
|
|
91 |
begin |
|
|
92 |
SL := TStringList.Create; |
|
|
93 |
SL.Add('The hUGETracker paste format is compatible with...'); |
|
|
94 |
SL.Add('ModPlug Tracker XM'); |
|
|
95 |
try |
|
|
96 |
for R := 0 to High(Selection) do begin |
|
|
97 |
S := ''; |
|
|
98 |
for C := 0 to High(Selection[R]) do |
|
|
99 |
S += SerializeCell(Selection[R, C]); |
|
|
100 |
SL.Add(S); |
|
|
101 |
end; |
|
|
102 |
|
|
|
103 |
Clipboard.AsText := SL.Text; |
|
|
104 |
finally |
|
|
105 |
SL.Free; |
|
|
106 |
end; |
|
|
107 |
end; |
|
|
108 |
|
| 92 |
end. |
109 |
end. |
| 93 |
|
110 |
|