Skip to content

Commit f1d3ff5

Browse files
committed
Add support for providing full filename on command line
This fixes an issue I had using the tool with filename completion by allowing the user to provide the .mid extension when specifying the base filename. It will strip that off before processing.
1 parent 510e928 commit f1d3ff5

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

midi2tones.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
*
5959
* midi2tones chopin
6060
*
61+
*
6162
* It will create a file in the same directory called "chopin.c" which contains
6263
* the C-language statement to intiialize an array called "score" with the bytestream.
6364
*
@@ -72,6 +73,9 @@
7273
* The <basefilename> is the base name, without an extension, for the input and
7374
* output files. It can contain directory path information, or not.
7475
*
76+
* If the <basefilename> provided by the user ends in .mid, that will be stripped off
77+
* before being used.
78+
*
7579
* The input file is <basefilename>.mid The output filename(s)
7680
* are the base file name with .c, .bin, and/or .log extensions.
7781
*
@@ -239,6 +243,7 @@
239243
* The MIT License (MIT)
240244
* Original work Copyright (c) 2011,2013,2015,2016, Len Shustek
241245
* Modified work Copyright (c) 2016, Scott Allen
246+
* Modified work Copyright (c) 2020, Ben Combee
242247
*
243248
* Permission is hereby granted, free of charge, to any person obtaining a copy
244249
* of this software and associated documentation files (the "Software"), to deal
@@ -325,8 +330,11 @@
325330
* -Prevent unnecessary "note off" commands from being generated by delaying
326331
* them until we see if a "note on" is generated before the next wait.
327332
* Ported from MIDITONES V1.14
333+
* 17 October 2020, Ben Combee, V1.0.1
334+
* -Support user providing full name of MIDI file on command line by stripping
335+
* off the .mid suffix if provided
328336
*/
329-
#define VERSION "1.0.0"
337+
#define VERSION "1.0.1"
330338

331339
/*--------------------------------------------------------------------------------------------
332340
@@ -1176,13 +1184,14 @@ int main (int argc, char *argv[]) {
11761184
char *filebasename;
11771185
#define MAXPATH 120
11781186
char filename[MAXPATH];
1187+
int filenamelen;
11791188
int tracknum;
11801189
int earliest_tracknum;
11811190
unsigned long earliest_time;
11821191
int notes_skipped = 0;
11831192
char *text;
11841193

1185-
printf ("MIDI2TONES V%s\n(C) 2011-2016 Len Shustek\n(C) 2016 Scott Allen\n", VERSION);
1194+
printf ("MIDI2TONES V%s\n(C) 2011-2016 Len Shustek\n(C) 2016 Scott Allen\n(C) 2020 Ben Combee", VERSION);
11861195
if (argc == 1) { /* no arguments */
11871196
SayUsage (argv[0]);
11881197
return 1;
@@ -1198,6 +1207,13 @@ int main (int argc, char *argv[]) {
11981207
}
11991208
filebasename = argv[argno];
12001209

1210+
/* strip off trailing .mid if provided by user */
1211+
1212+
filenamelen = strlength(filebasename);
1213+
if (filenamelen > 4 && charcmp(filebasename + filenamelen - 4, ".mid")) {
1214+
filebasename[filenamelen - 4] = 0;
1215+
}
1216+
12011217
/* if alternate output format, overide options with required values */
12021218
if (alt_out) {
12031219
num_tonegens = 1;

0 commit comments

Comments
 (0)