This repository was archived by the owner on Oct 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMidiImportPlugin.cs
90 lines (74 loc) · 2.9 KB
/
MidiImportPlugin.cs
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
using Godot;
using System;
using Godot.Collections;
[Tool]
public class MidiImportPlugin : EditorImportPlugin
{
/// Importer for .midi files.
/// This importer is used to import MIDI files into Godot.
public override String GetImporterName()
{
// The name of the importer.
return "midi.importer.godotmidi";
}
public override String GetVisibleName()
{
// The name of the importer as it appears in the import dialog.
return "Standard Midi File (MIDI)";
}
public override Godot.Collections.Array GetRecognizedExtensions()
{
// The list of file extensions that this importer can handle.
return new Godot.Collections.Array { "midi", "mid" };
}
public override String GetSaveExtension()
{
// The extension that will be used for the imported resource.
return "res";
}
public override String GetResourceType()
{
// The type of the imported resource.
return "Animation";
}
public override int GetPresetCount()
{
// The number of presets that this importer supports.
return 0;
}
public override String GetPresetName(int preset)
{
// The name of the preset at the given index.
return "Default";
}
public override Godot.Collections.Array GetImportOptions(int preset)
{
// The list of import options that this importer supports.
return new Godot.Collections.Array { };
}
public override int Import(String source_file, String save_path, Godot.Collections.Dictionary options, Godot.Collections.Array platform_variants, Godot.Collections.Array gen_files)
{
// The actual import function.
// This function is called when the user clicks on the "Import" button in the import dialog.
// The source_file parameter is the path to the file that the user wants to import.
// The save_path parameter is the path where the imported resource should be saved.
// The options parameter contains the values of the import options.
// The platform_variants parameter contains the values of the platform variants.
// The gen_files parameter contains the values of the generated files.
// Create a new MIDI object for conversion to godot readable format.
MIDI midi = new MIDI();
GD.Print(save_path);
// Load the MIDI file into the godot node
Animation midi_res = midi.LoadFromFile(source_file);
// Save the MIDI resource to disk
if (midi != null)
{
String save_file = save_path + "." + GetSaveExtension();
Error status = ResourceSaver.Save(save_file, midi_res);
GD.Print("MIDI resource file saved to: " + save_file);
GD.Print("Resource save status: " + status);
return 0;
}
return 1;
}
}