-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from loveemu-lab repository <https://github.com/loveemu/lovee…
- Loading branch information
Showing
15 changed files
with
2,718 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>PetiteMM</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.6 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@setlocal | ||
@set PMMOPTS= | ||
@if "%~1"=="" @goto usage | ||
@for %%a in (%*) do @java -jar "%~dp0PetiteMM.jar" %PMMOPTS% "%%~fa" | ||
@goto heaven | ||
:usage | ||
@java -jar "%~dp0PetiteMM.jar" | ||
:heaven | ||
@endlocal | ||
@pause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
Petite MIDI (SMF) to MML Converter | ||
http://loveemu.googlecode.com/ | ||
|
||
=== What is PetiteMM? === | ||
|
||
PetiteMM is a SMF to MML converter. | ||
It extracts only notes from a sequence. | ||
|
||
Features: | ||
- Supports triplets such as c12d12e12 | ||
- No polyphonic support, only one note will be converted | ||
- Timings between tracks will never desync like some other converters | ||
|
||
=== How to use === | ||
|
||
PetiteMM is a Java tool. | ||
If you do not have Java, install it first. | ||
http://java.com/download/ | ||
|
||
Drag and drop .mid files into PetiteMM.bat, | ||
and .mml files will be saved in the input directory. | ||
|
||
You can run it manually by java -jar PetiteMM.jar <arguments> | ||
There are some conversion options. Run the tool with no arguments for the list of options. | ||
|
||
=== Special thanks === | ||
|
||
TinyMM, a similar converter, PetiteMM will never be created without it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
|
||
import javax.sound.midi.InvalidMidiDataException; | ||
import javax.sound.midi.MidiSystem; | ||
|
||
import com.googlecode.loveemu.PetiteMM.Midi2MML; | ||
|
||
public class PetiteMM { | ||
|
||
/** | ||
* Removes the extension from a filename. | ||
* @param filename the filename to query, null returns null | ||
* @return the filename minus the extension | ||
*/ | ||
public static String removeExtension(String filename) | ||
{ | ||
if (filename == null) | ||
return null; | ||
|
||
int extensionIndex = filename.lastIndexOf("."); | ||
if (extensionIndex == -1) | ||
return filename; | ||
|
||
String separator = System.getProperty("file.separator"); | ||
int lastSeparatorIndex = filename.lastIndexOf(separator); | ||
if (extensionIndex > lastSeparatorIndex) | ||
return filename.substring(0, extensionIndex); | ||
else | ||
return filename; | ||
} | ||
|
||
/** | ||
* Convert the given MIDI file into MML. | ||
* @param args Parameters, specify the empty array for details. | ||
*/ | ||
public static void main(String[] args) | ||
{ | ||
boolean showAbout = false; | ||
Midi2MML opt = new Midi2MML(); | ||
String mmlFileName = null; | ||
|
||
// list of available option switches | ||
final String[] argsAvail = { | ||
"-o", "<filename>", "Specify the output MML filename.", | ||
"--dots", "<count>", "Maximum dot counts allowed for dotted-note, -1 for infinity. (default=" + Midi2MML.DEFAULT_MAX_DOT_COUNT + ")", | ||
"--timebase", "<TPQN>", "Timebase of target MML, " + Midi2MML.RESOLUTION_AS_IS + " to keep the input timebase. (default=" + Midi2MML.DEFAULT_RESOLUTION + ")", | ||
"--input-timebase", "<TPQN>", "Timebase of input sequence, " + Midi2MML.RESOLUTION_AS_IS + " to keep the input timebase. (default=" + Midi2MML.RESOLUTION_AS_IS + ")", | ||
"--quantize-precision", "<length>", "Specify the minimum note length for quantization.", | ||
"--no-quantize", "", "Prevent adjusting note length. Result will be more accurate but more complicated.", | ||
"--octave-reverse", "", "Swap the octave symbol.", | ||
"--use-triplet", "", "Use triplet syntax if possible. (really not so smart)", | ||
}; | ||
|
||
int argi = 0; | ||
|
||
//args = new String[] { "test.mid" }; | ||
|
||
// dispatch option switches | ||
while (argi < args.length && args[argi].startsWith("-")) | ||
{ | ||
if (args[argi].equals("-o")) | ||
{ | ||
if (argi + 1 >= args.length) | ||
{ | ||
throw new IllegalArgumentException("Too few arguments for " + args[argi]); | ||
} | ||
mmlFileName = args[argi + 1]; | ||
argi += 1; | ||
} | ||
else if (args[argi].equals("--dots")) | ||
{ | ||
if (argi + 1 >= args.length) | ||
{ | ||
throw new IllegalArgumentException("Too few arguments for " + args[argi]); | ||
} | ||
opt.setMaxDots(Integer.parseInt(args[argi + 1])); | ||
argi += 1; | ||
} | ||
else if (args[argi].equals("--timebase")) | ||
{ | ||
if (argi + 1 >= args.length) | ||
{ | ||
throw new IllegalArgumentException("Too few arguments for " + args[argi]); | ||
} | ||
opt.setTargetResolution(Integer.parseInt(args[argi + 1])); | ||
argi += 1; | ||
} | ||
else if (args[argi].equals("--input-timebase")) | ||
{ | ||
if (argi + 1 >= args.length) | ||
{ | ||
throw new IllegalArgumentException("Too few arguments for " + args[argi]); | ||
} | ||
opt.setInputResolution(Integer.parseInt(args[argi + 1])); | ||
argi += 1; | ||
} | ||
else if (args[argi].equals("--quantize-precision")) | ||
{ | ||
if (argi + 1 >= args.length) | ||
{ | ||
throw new IllegalArgumentException("Too few arguments for " + args[argi]); | ||
} | ||
opt.setQuantizePrecision(Integer.parseInt(args[argi + 1])); | ||
argi += 1; | ||
} | ||
else if (args[argi].equals("--no-quantize")) | ||
{ | ||
opt.setQuantizationEnabled(false); | ||
} | ||
else if (args[argi].equals("--octave-reverse")) | ||
{ | ||
opt.setOctaveReversed(true); | ||
} | ||
else if (args[argi].equals("--use-triplet")) | ||
{ | ||
opt.setTripletPreference(true); | ||
} | ||
else | ||
{ | ||
throw new IllegalArgumentException("Unsupported option [" + args[argi] + "]"); | ||
} | ||
argi++; | ||
} | ||
|
||
// show about the program and exit, if needed | ||
if (argi >= args.length || showAbout) | ||
{ | ||
System.out.println(Midi2MML.NAME + " " + Midi2MML.VERSION + " by " + Midi2MML.AUTHOR); | ||
System.out.println(Midi2MML.WEBSITE); | ||
System.out.println(); | ||
|
||
System.out.println("Syntax: PetiteMM <options> input.mid"); | ||
if (argsAvail.length > 0) | ||
System.out.println("Options:"); | ||
for (int i = 0; i < argsAvail.length / 3; i++) | ||
{ | ||
System.out.format("%-20s %-9s %s\n", argsAvail[i * 3], argsAvail[i * 3 + 1], argsAvail[i * 3 + 2]); | ||
} | ||
|
||
System.exit(1); | ||
} | ||
|
||
// target must be a single file | ||
if (argi + 1 < args.length) | ||
{ | ||
throw new IllegalArgumentException("Too many arguments."); | ||
} | ||
|
||
// convert the given file | ||
File midiFile = new File(args[argi]); | ||
if (mmlFileName == null) | ||
{ | ||
mmlFileName = PetiteMM.removeExtension(args[argi]) + ".mml"; | ||
} | ||
File mmlFile = new File(mmlFileName); | ||
|
||
Midi2MML converter = new Midi2MML(opt); | ||
FileWriter fileWriter = null; | ||
boolean succeeded = false; | ||
try { | ||
if (!midiFile.exists()) | ||
throw new FileNotFoundException(midiFile.getName() + " (The system cannot find the file specified)"); | ||
|
||
StringWriter strWriter = new StringWriter(); | ||
BufferedWriter writer = new BufferedWriter(strWriter); | ||
converter.writeMML(MidiSystem.getSequence(midiFile), writer); | ||
writer.flush(); | ||
|
||
fileWriter = new FileWriter(mmlFile); | ||
fileWriter.write(strWriter.toString()); | ||
|
||
succeeded = true; | ||
} catch (InvalidMidiDataException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} finally { | ||
if (fileWriter != null) | ||
{ | ||
try { | ||
fileWriter.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
System.exit(succeeded ? 0 : 1); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.googlecode.loveemu.PetiteMM; | ||
|
||
public class MMLEvent { | ||
|
||
/** | ||
* MML command text. | ||
*/ | ||
private String command; | ||
|
||
/** | ||
* MML command parameters. | ||
*/ | ||
private String[] params; | ||
|
||
/** | ||
* Construct a new MML event. | ||
*/ | ||
public MMLEvent() | ||
{ | ||
this(null, null); | ||
} | ||
|
||
/** | ||
* Construct a new MML event. | ||
* @param command MML command text. | ||
*/ | ||
public MMLEvent(String command) { | ||
this(command, null); | ||
} | ||
|
||
/** | ||
* Construct a new MML event. | ||
* @param command MML command text. | ||
* @param params MML command parameters. | ||
*/ | ||
public MMLEvent(String command, String[] params) { | ||
this.command = command; | ||
this.params = params; | ||
} | ||
|
||
/** | ||
* Get command text. | ||
* @return MML command text without parameters. | ||
*/ | ||
public String getCommand() { | ||
return command; | ||
} | ||
|
||
/** | ||
* Set command text. | ||
* @param command MML commend text. | ||
*/ | ||
public void setCommand(String command) { | ||
this.command = command; | ||
} | ||
|
||
/** | ||
* Get MML command parameter texts. | ||
* @return Array of MML command parameters. | ||
*/ | ||
public String[] getParams() { | ||
return params; | ||
} | ||
|
||
/** | ||
* Set MML command parameter texts. | ||
* @param params Array of MML command parameters. | ||
*/ | ||
public void setParams(String[] params) { | ||
this.params = params; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
StringBuffer buf = new StringBuffer(); | ||
if (command != null) { | ||
buf.append(command); | ||
} | ||
if (params != null) { | ||
for (int i = 0; i < params.length; i++) { | ||
if (i != 0) | ||
buf.append(","); | ||
buf.append(params[i]); | ||
} | ||
} | ||
return buf.toString(); | ||
} | ||
} |
Oops, something went wrong.