aboutsummaryrefslogtreecommitdiffstats
path: root/src/base/UFiles.pas
blob: 0495dfbba9824f21a5c77c44d5fae032cc06906a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
{* UltraStar Deluxe - Karaoke Game
 *
 * UltraStar Deluxe is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; see the file COPYING. If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 * $URL$
 * $Id$
 *}

unit UFiles;

interface

{$IFDEF FPC}
  {$MODE Delphi}
{$ENDIF}
{$I switches.inc}

uses
  SysUtils,
  ULog,
  UMusic,
  USongs,
  USong;

procedure ResetSingTemp;

function  SaveSong(Song: TSong; Lines: TLines; Name: string; Relative: boolean): boolean;

var
  SongFile: TextFile;   // all procedures in this unit operates on this file
  FileLineNo: integer;  //Line which is readed at Last, for error reporting

  // variables available for all procedures
  Base    : array[0..1] of integer;
  Rel     : array[0..1] of integer;
  Mult    : integer = 1;
  MultBPM : integer = 4;

implementation

uses
  TextGL,
  UIni,
  UNote,
  UPlatform;

//--------------------
// Resets the temporary Sentence Arrays for each Player and some other Variables
//--------------------
procedure ResetSingTemp;
var
  Count:  integer;
begin
  SetLength(Lines, Length(Player));
  for Count := 0 to High(Player) do begin
    SetLength(Lines[Count].Line, 1);
    SetLength(Lines[Count].Line[0].Note, 0);
    Lines[Count].Line[0].Lyric := '';
    Player[Count].Score := 0;
    Player[Count].LengthNote := 0;
    Player[Count].HighNote := -1;
  end;

  (* FIXME
  //Reset Path and Filename Values to Prevent Errors in Editor
  if assigned( CurrentSong ) then
  begin
    SetLength(CurrentSong.BPM, 0);
    CurrentSong.Path := '';
    CurrentSong.FileName := '';
  end;
  *)
  
//  CurrentSong := nil;
end;


//--------------------
// Saves a Song
//--------------------
function SaveSong(Song: TSong; Lines: TLines; Name: string; Relative: boolean): boolean;
var
  C:      integer;
  N:      integer;
  S:      string;
  B:      integer;
  RelativeSubTime:    integer;
  NoteState: String;

begin
//  Relative := true; // override (idea - use shift+S to save with relative)
  AssignFile(SongFile, Name);
  Rewrite(SongFile);

  Writeln(SongFile, '#TITLE:' + Song.Title + '');
  Writeln(SongFile, '#ARTIST:' + Song.Artist);

  if Song.Creator     <> '' then    Writeln(SongFile, '#CREATOR:'     + Song.Creator);
  if Song.Edition     <> 'Unknown' then Writeln(SongFile, '#EDITION:' + Song.Edition);
  if Song.Genre       <> 'Unknown' then   Writeln(SongFile, '#GENRE:' + Song.Genre);
  if Song.Language    <> 'Unknown' then    Writeln(SongFile, '#LANGUAGE:'    + Song.Language);

  Writeln(SongFile, '#MP3:' + Song.Mp3);

  if Song.Cover       <> '' then    Writeln(SongFile, '#COVER:'       + Song.Cover);
  if Song.Background  <> '' then    Writeln(SongFile, '#BACKGROUND:'  + Song.Background);
  if Song.Video       <> '' then    Writeln(SongFile, '#VIDEO:'       + Song.Video);
  if Song.VideoGAP    <> 0  then    Writeln(SongFile, '#VIDEOGAP:'    + FloatToStr(Song.VideoGAP));
  if Song.Resolution  <> 4  then    Writeln(SongFile, '#RESOLUTION:'  + IntToStr(Song.Resolution));
  if Song.NotesGAP    <> 0  then    Writeln(SongFile, '#NOTESGAP:'    + IntToStr(Song.NotesGAP));
  if Song.Start       <> 0  then    Writeln(SongFile, '#START:'       + FloatToStr(Song.Start));
  if Song.Finish      <> 0  then    Writeln(SongFile, '#END:'         + IntToStr(Song.Finish));
  if Relative               then    Writeln(SongFile, '#RELATIVE:yes');

  Writeln(SongFile, '#BPM:' + FloatToStr(Song.BPM[0].BPM / 4));
  Writeln(SongFile, '#GAP:' + FloatToStr(Song.GAP));

  RelativeSubTime := 0;
  for B := 1 to High(CurrentSong.BPM) do
    Writeln(SongFile, 'B ' + FloatToStr(CurrentSong.BPM[B].StartBeat) + ' ' + FloatToStr(CurrentSong.BPM[B].BPM/4));

  for C := 0 to Lines.High do begin
    for N := 0 to Lines.Line[C].HighNote do begin
      with Lines.Line[C].Note[N] do begin


        //Golden + Freestyle Note Patch
        case Lines.Line[C].Note[N].NoteType of
          ntFreestyle: NoteState := 'F ';
          ntNormal: NoteState := ': ';
          ntGolden: NoteState := '* ';
        end; // case
        S := NoteState + IntToStr(Start-RelativeSubTime) + ' ' + IntToStr(Length) + ' ' + IntToStr(Tone) + ' ' + Text;


        Writeln(SongFile, S);
      end; // with
    end; // N

    if C < Lines.High then begin      // don't write end of last sentence
      if not Relative then
        S := '- ' + IntToStr(Lines.Line[C+1].Start)
      else begin
        S := '- ' + IntToStr(Lines.Line[C+1].Start - RelativeSubTime) +
          ' ' + IntToStr(Lines.Line[C+1].Start - RelativeSubTime);
        RelativeSubTime := Lines.Line[C+1].Start;
      end;
      Writeln(SongFile, S);
    end;

  end; // C


  Writeln(SongFile, 'E');
  CloseFile(SongFile);

  Result := true;
end;

end.