Skip to content

Commit e3694a5

Browse files
committed
1.1.0
- Update version number - Add console vars - Limit keyboard range to 127 (FL has 131 keys) - Fix issue with FLParser's tracks being incorrect - Use less ram by using a temp file instead to store parsed tracks - Fix issue with MMF not being able to save super large midis - Fix build script to build in release mode and not debug (oops)
1 parent 69442ae commit e3694a5

File tree

5 files changed

+71
-24
lines changed

5 files changed

+71
-24
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ csharp_new_line_between_query_expression_clauses = true
131131
csharp_indent_block_contents = true
132132
csharp_indent_braces = false
133133
csharp_indent_case_contents = true
134-
csharp_indent_case_contents_when_block = true
134+
csharp_indent_case_contents_when_block = false
135135
csharp_indent_labels = no_change
136136
csharp_indent_switch_labels = true
137137

Program.cs

+55-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ namespace flp2midi
1515
{
1616
class Program
1717
{
18+
static bool ForceColor { get; set; }
19+
static bool DisableEcho { get; set; }
20+
1821
//TODO: Actually support feed correctly
1922
static IEnumerable<Note> EchoNotes(IEnumerable<Note> notes, byte echoamount, uint feed, uint time, int ppq)
2023
{
@@ -44,8 +47,12 @@ static void Main(string[] args)
4447
}
4548

4649
var filePath = args[0];
50+
var tempFile = Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileName(filePath) + ".mid.tmp");
51+
var streams = new ParallelStream(File.Open(tempFile, FileMode.Create));
52+
53+
GetArgs(args);
4754

48-
Console.WriteLine("flp2midi | Version: 1.0.0");
55+
Console.WriteLine("flp2midi | Version: 1.1.0");
4956
Console.WriteLine("Loading FL Studio project file...");
5057

5158
Project proj = Project.Load(filePath, false);
@@ -77,7 +84,7 @@ static void Main(string[] args)
7784

7885
return c.Value
7986
.OrderBy(n => n.Position)
80-
.Select(n => new Note(colorchan ? n.Color : channel, n.Key, Math.Min((byte)127, n.Velocity), (double)n.Position, (double)n.Position + (double)n.Length))
87+
.Select(n => new Note((colorchan || ForceColor) ? n.Color : channel, Math.Min((byte)127, n.Key), Math.Min((byte)127, n.Velocity), (double)n.Position, (double)n.Position + (double)n.Length))
8188
.ToArray();
8289
});
8390

@@ -91,7 +98,7 @@ static void Main(string[] args)
9198

9299
var trackID = 0;
93100

94-
MemoryStream[] streams = new MemoryStream[proj.Tracks.Length];
101+
//MemoryStream[] streams = new MemoryStream[proj.Tracks.Length];
95102

96103
var tracks = proj.Tracks.Where(t => t.Items.Count != 0).OrderBy(t =>
97104
t.Items.Select(i =>
@@ -112,7 +119,7 @@ static void Main(string[] args)
112119
4 - Unknown
113120
5 - Tempo Events
114121
*/
115-
122+
116123
/*
117124
* Modes:
118125
* 10 - Smooth
@@ -136,9 +143,10 @@ static void Main(string[] args)
136143

137144
ParallelFor(0, tracks.Length, Environment.ProcessorCount, new CancellationToken(false), i =>
138145
{
139-
streams[i] = new MemoryStream();
146+
//streams[i] = new MemoryStream();
140147

141-
var trackWriter = new MidiWriter(streams[i]);
148+
var stream = new BufferedStream(streams.GetStream(i), 1 << 24);
149+
var trackWriter = new MidiWriter(stream);
142150

143151
var track = tracks[i];
144152

@@ -160,7 +168,7 @@ static void Main(string[] args)
160168

161169
if(channel.Data is GeneratorData data)
162170
{
163-
if(data.EchoFeed > 0)
171+
if(data.EchoFeed > 0 && !DisableEcho)
164172
{
165173
shifted = EchoNotes(shifted, data.Echo, data.EchoFeed, data.EchoTime, proj.Ppq);
166174
}
@@ -178,13 +186,16 @@ static void Main(string[] args)
178186
}).MergeAll().TrimStart();
179187

180188
trackWriter.Write(notes.ExtractEvents());
189+
stream.Close();
181190

182191
lock(l)
183192
{
184193
Console.WriteLine($"Generated track {i + 1}, {(trackID++) + 1}/{tracks.Length}");
185194
}
186195
});
187196

197+
streams.CloseAllStreams();
198+
188199
var writer = new MidiWriter(Path.Combine(Path.GetDirectoryName(filePath), Path.GetFileName(filePath) + ".mid"));
189200
writer.Init((ushort)proj.Ppq);
190201
writer.InitTrack();
@@ -195,20 +206,51 @@ static void Main(string[] args)
195206
{
196207
Console.WriteLine($"Writing track {i + 1}/{tracks.Length}");
197208

198-
streams[i].Position = 0;
209+
var stream = streams.GetStream(i, true);
210+
211+
stream.Position = 0;
199212
unchecked
200213
{
201-
writer.WriteTrack(streams[i]);
214+
writer.WriteTrack(stream);
202215
}
203-
streams[i].Close();
216+
stream.Close();
204217
}
205218

206219
writer.Close();
220+
streams.CloseAllStreams();
221+
streams.Dispose();
222+
File.Delete(tempFile);
207223

208224
Console.WriteLine("Press any key to exit... ");
209225
Console.ReadKey();
210226
}
211227

228+
static void GetArgs(string[] args)
229+
{
230+
for(var i = 0; i < args.Length; i++)
231+
{
232+
switch(args[i])
233+
{
234+
case "-fc":
235+
case "--forcecolor":
236+
{
237+
ForceColor = true;
238+
break;
239+
}
240+
case "-de":
241+
case "--disable-echo":
242+
{
243+
DisableEcho = true;
244+
break;
245+
}
246+
default:
247+
{
248+
break;
249+
}
250+
}
251+
}
252+
}
253+
212254
static void ParallelFor(int from, int to, int threads, CancellationToken cancel, Action<int> func)
213255
{
214256
Dictionary<int, Task> tasks = new Dictionary<int, Task>();
@@ -221,9 +263,11 @@ void RunTask(int i)
221263
try
222264
{
223265
func(i);
266+
}
267+
finally
268+
{
224269
completed.Add(i);
225270
}
226-
catch(Exception e) { }
227271
});
228272
tasks.Add(i, t);
229273
t.Start();

build.bat

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ git submodule init
1111
git submodule update
1212

1313
ECHO Building...
14-
dotnet publish -p:PublishProfile="Windows - Release x64"
15-
dotnet publish -p:PublishProfile="Windows - Release x86"
16-
dotnet publish -p:PublishProfile="Windows - Release Arm"
17-
dotnet publish -p:PublishProfile="Linux - Release x64"
18-
dotnet publish -p:PublishProfile="Linux - Release Arm"
19-
dotnet publish -p:PublishProfile="OSX - Release x64"
14+
dotnet publish -c Release -p:PublishProfile="Windows - Release x64"
15+
dotnet publish -c Release -p:PublishProfile="Windows - Release x86"
16+
dotnet publish -c Release -p:PublishProfile="Windows - Release Arm"
17+
dotnet publish -c Release -p:PublishProfile="Linux - Release x64"
18+
dotnet publish -c Release -p:PublishProfile="Linux - Release Arm"
19+
dotnet publish -c Release -p:PublishProfile="OSX - Release x64"
2020

2121
ECHO Archiving...
2222
7z a -t7z -mmt16 -mx9 .\builds\flp2midi-win-x64.7z .\bin\x64\Release\net5.0\publish\win-x64\*.dll .\bin\x64\Release\net5.0\publish\win-x64\flp2midi.exe

build.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ git submodule init
1111
git submodule update
1212

1313
echo "Building..."
14-
dotnet publish -p:PublishProfile="Windows - Release x64"
15-
dotnet publish -p:PublishProfile="Windows - Release x86"
16-
dotnet publish -p:PublishProfile="Windows - Release Arm"
17-
dotnet publish -p:PublishProfile="Linux - Release x64"
18-
dotnet publish -p:PublishProfile="Linux - Release Arm"
19-
dotnet publish -p:PublishProfile="OSX - Release x64"
14+
dotnet publish -c Release -p:PublishProfile="Windows - Release x64"
15+
dotnet publish -c Release -p:PublishProfile="Windows - Release x86"
16+
dotnet publish -c Release -p:PublishProfile="Windows - Release Arm"
17+
dotnet publish -c Release -p:PublishProfile="Linux - Release x64"
18+
dotnet publish -c Release -p:PublishProfile="Linux - Release Arm"
19+
dotnet publish -c Release -p:PublishProfile="OSX - Release x64"
2020

2121
echo "Archiving..."
2222
7z a -t7z -mmt16 -mx9 ./builds/flp2midi-win-x64.7z ./bin/x64/Release/net5.0/publish/win-x64/*.dll ./bin/x64/Release/net5.0/publish/win-x64/flp2midi.exe

flp2midi.csproj

+3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@
2828
</PropertyGroup>
2929

3030
<ItemGroup>
31+
<Compile Remove="builds\**" />
3132
<Compile Remove="external\**" />
33+
<EmbeddedResource Remove="builds\**" />
3234
<EmbeddedResource Remove="external\**" />
35+
<None Remove="builds\**" />
3336
<None Remove="external\**" />
3437
</ItemGroup>
3538

0 commit comments

Comments
 (0)