Commit 893c8f6

Nick committed on
Copying/Pasting mostly done
commit 893c8f63dfe1440baa9bf98012bc31bdefcb8e1d parent ac4ea0a
4 changed files +89−34
Modifiedclipboardutils.pas +42−25
@@ -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
Modifiedcodegen.pas +6−6
@@ -6,7 +6,7 @@ interface
6 6
7 uses 7 uses
8 Classes, SysUtils, math, 8 Classes, SysUtils, math,
9 Waves, Instruments, Song, 9 Waves, Instruments, Song, Utils,
10 HugeDatatypes, Constants, dialogs; 10 HugeDatatypes, Constants, dialogs;
11 11
12 function RenderOrderTable(OrderMatrix: TOrderMatrix): String; 12 function RenderOrderTable(OrderMatrix: TOrderMatrix): String;
@@ -50,7 +50,7 @@ begin
50 Res.Add('order3: dw ' + ArrayHelper(OrderMatrix[2])); 50 Res.Add('order3: dw ' + ArrayHelper(OrderMatrix[2]));
51 Res.Add('order4: dw ' + ArrayHelper(OrderMatrix[3])); 51 Res.Add('order4: dw ' + ArrayHelper(OrderMatrix[3]));
52 52
53 Result := Res.GetText; 53 Result := Res.Text;
54 Res.Free; 54 Res.Free;
55 end; 55 end;
56 56
@@ -75,7 +75,7 @@ begin
75 SL.Free; 75 SL.Free;
76 end; 76 end;
77 77
78 Result := ResultSL.GetText; 78 Result := ResultSL.Text;
79 ResultSL.Free; 79 ResultSL.Free;
80 end; 80 end;
81 81
@@ -93,7 +93,7 @@ begin
93 SL.Add(NoteToDriverMap.KeyData[Cell.Note]); 93 SL.Add(NoteToDriverMap.KeyData[Cell.Note]);
94 94
95 SL.Add(IntToStr(Cell.Instrument)); 95 SL.Add(IntToStr(Cell.Instrument));
96 SL.Add('$' + HexStr((Cell.EffectCode shl 8) or Cell.EffectParams.Value, 3)); 96 SL.Add('$' + EffectCodeToStr(Cell.EffectCode, Cell.EffectParams));
97 97
98 // RGBDS thinks you're defining a new macro if you don't have a space first. 98 // RGBDS thinks you're defining a new macro if you don't have a space first.
99 Result := ' dn ' + SL.DelimitedText; 99 Result := ' dn ' + SL.DelimitedText;
@@ -111,7 +111,7 @@ begin
111 for I := Low(TPattern) to High(TPattern) do 111 for I := Low(TPattern) to High(TPattern) do
112 SL.Add(RenderCell(Pattern[I])); 112 SL.Add(RenderCell(Pattern[I]));
113 113
114 Result := SL.GetText; 114 Result := SL.Text;
115 SL.Free; 115 SL.Free;
116 end; 116 end;
117 117
@@ -132,7 +132,7 @@ begin
132 SL.Free; 132 SL.Free;
133 end; 133 end;
134 134
135 Result := ResultSL.GetText; 135 Result := ResultSL.Text;
136 ResultSL.Free; 136 ResultSL.Free;
137 end; 137 end;
138 138
Modifiedtrackergrid.pas +35−3
@@ -84,7 +84,8 @@ type
84 procedure RenderCell(const Cell: TCell); 84 procedure RenderCell(const Cell: TCell);
85 85
86 procedure SetHighlightedRow(Row: Integer); 86 procedure SetHighlightedRow(Row: Integer);
87 87 procedure SetSelectionGridRect(R: TRect);
88 function GetSelectionGridRect: TRect;
88 function GetEffectColor(EffectCode: Integer): TColor; 89 function GetEffectColor(EffectCode: Integer): TColor;
89 function SelectionsToRect(S1, S2: TSelectionPos): TRect; 90 function SelectionsToRect(S1, S2: TSelectionPos): TRect;
90 function SelectionToRect(Selection: TSelectionPos): TRect; 91 function SelectionToRect(Selection: TSelectionPos): TRect;
@@ -95,7 +96,7 @@ type
95 Cursor, Other: TSelectionPos; 96 Cursor, Other: TSelectionPos;
96 ColumnWidth, RowHeight: Integer; 97 ColumnWidth, RowHeight: Integer;
97 property HighlightedRow: Integer read FHighlightedRow write SetHighlightedRow; 98 property HighlightedRow: Integer read FHighlightedRow write SetHighlightedRow;
98 99 property SelectionGridRect: TRect read GetSelectionGridRect write SetSelectionGridRect;
99 procedure LoadPattern(Idx: Integer; Pat: PPattern); 100 procedure LoadPattern(Idx: Integer; Pat: PPattern);
100 end; 101 end;
101 102
@@ -256,7 +257,7 @@ begin
256 end; 257 end;
257 end; 258 end;
258 259
259 if not (ssShift in Shift) then 260 if not (ssShift in Shift) and not(ssCtrl in Shift) then
260 Other := Cursor; 261 Other := Cursor;
261 Selecting := ssShift in Shift; 262 Selecting := ssShift in Shift;
262 263
@@ -281,6 +282,7 @@ begin
281 end; 282 end;
282 Other.X := Cursor.X + X; 283 Other.X := Cursor.X + X;
283 Other.Y := Cursor.Y + Y; 284 Other.Y := Cursor.Y + Y;
285 Cursor.SelectedPart := Low(TCellPart);
284 Other.SelectedPart := High(TCellPart); 286 Other.SelectedPart := High(TCellPart);
285 except 287 except
286 on E: Exception do 288 on E: Exception do
@@ -291,8 +293,21 @@ begin
291 end; 293 end;
292 294
293 procedure TTrackerGrid.DoCopy(var Msg: TLMessage); 295 procedure TTrackerGrid.DoCopy(var Msg: TLMessage);
296 var
297 Selection: TSelection;
298 R, C: Integer;
299 Rect: TRect;
294 begin 300 begin
301 Rect := SelectionGridRect;
302 SetLength(Selection, Rect.Height+1);
303 for R := 0 to Rect.Height do begin
304 SetLength(Selection[R], Rect.Width+1);
305 for C := 0 to Rect.Width do begin
306 Selection[R, C] := Patterns[Rect.Left+C]^[Rect.Top+R];
307 end;
308 end;
295 309
310 CopyCells(Selection);
296 end; 311 end;
297 312
298 procedure TTrackerGrid.DoCut(var Msg: TLMessage); 313 procedure TTrackerGrid.DoCut(var Msg: TLMessage);
@@ -454,6 +469,23 @@ begin
454 if FHighlightedRow >= 0 then Invalidate; 469 if FHighlightedRow >= 0 then Invalidate;
455 end; 470 end;
456 471
472 procedure TTrackerGrid.SetSelectionGridRect(R: TRect);
473 begin
474 Cursor.X := R.Left;
475 Other.X := R.Right;
476 Cursor.Y := R.Top;
477 Other.Y := R.Bottom;
478 end;
479
480 function TTrackerGrid.GetSelectionGridRect: TRect;
481 begin
482 Result := TRect.Create(
483 TPoint.Create(Cursor.X, Cursor.Y),
484 TPoint.Create(Other.X, Other.Y),
485 True
486 );
487 end;
488
457 function TTrackerGrid.GetEffectColor(EffectCode: Integer): TColor; 489 function TTrackerGrid.GetEffectColor(EffectCode: Integer): TColor;
458 begin 490 begin
459 Result := clBlack; 491 Result := clBlack;
Modifiedutils.pas +6−0
@@ -18,6 +18,7 @@ type
18 18
19 function ConvertWaveform(Waveform: TWave): T4bitWave; 19 function ConvertWaveform(Waveform: TWave): T4bitWave;
20 procedure BlankPattern(Pat: PPattern); 20 procedure BlankPattern(Pat: PPattern);
21 function EffectCodeToStr(Code: Integer; Params: TEffectParams): String;
21 22
22 implementation 23 implementation
23 24
@@ -79,5 +80,10 @@ begin
79 end; 80 end;
80 end; 81 end;
81 82
83 function EffectCodeToStr(Code: Integer; Params: TEffectParams): String;
84 begin
85 Result := HexStr((Code shl 8) or Params.Value, 3);
86 end;
87
82 end. 88 end.
83 89