Skip to content

Commit e8488fb

Browse files
committed
Add MIDI file track selection
1 parent d8520f7 commit e8488fb

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

Assets/MidiAnim/Editor/MidiAnimImporter.cs

100644100755
+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ namespace MidiAnim
1212
[ScriptedImporter(1, "midianim")]
1313
class MidiAnimImporter : ScriptedImporter
1414
{
15+
[SerializeField] int _trackIndex = 0;
1516
[SerializeField] float _bpm = 120;
1617
[SerializeField] bool _gateEasing = false;
1718
[SerializeField] float _attackTime = 0.1f;
@@ -20,7 +21,7 @@ class MidiAnimImporter : ScriptedImporter
2021
public override void OnImportAsset(AssetImportContext context)
2122
{
2223
var song = MidiFileLoader.Load(File.ReadAllBytes(context.assetPath));
23-
var seq = new MidiTrackSequencer(song.tracks[0], song.division, _bpm);
24+
var seq = new MidiTrackSequencer(song.tracks[_trackIndex], song.division, _bpm);
2425

2526
var clip = new MidiClip(_bpm);
2627
if (_gateEasing) clip.EnableEasing(_attackTime, _releaseTime);

Assets/MidiAnim/Editor/MidiAnimImporterEditor.cs

100644100755
+4
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ namespace MidiAnim
1212
[CustomEditor(typeof(MidiAnimImporter))]
1313
class MidiAnimImporterEditor : ScriptedImporterEditor
1414
{
15+
SerializedProperty _trackIndex;
1516
SerializedProperty _bpm;
1617
SerializedProperty _gateEasing;
1718
SerializedProperty _attackTime;
1819
SerializedProperty _releaseTime;
1920

2021
static class Styles
2122
{
23+
public static readonly GUIContent TrackIndex = new GUIContent("Track Index");
2224
public static readonly GUIContent BPM = new GUIContent("BPM");
2325
}
2426

@@ -29,6 +31,7 @@ public override void OnEnable()
2931
{
3032
base.OnEnable();
3133

34+
_trackIndex = serializedObject.FindProperty("_trackIndex");
3235
_bpm = serializedObject.FindProperty("_bpm");
3336
_gateEasing = serializedObject.FindProperty("_gateEasing");
3437
_attackTime = serializedObject.FindProperty("_attackTime");
@@ -37,6 +40,7 @@ public override void OnEnable()
3740

3841
public override void OnInspectorGUI()
3942
{
43+
EditorGUILayout.PropertyField(_trackIndex, Styles.TrackIndex);
4044
EditorGUILayout.PropertyField(_bpm, Styles.BPM);
4145
EditorGUILayout.PropertyField(_gateEasing);
4246

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ There are a few settings in the inspector.
3232

3333
![inspector](https://i.imgur.com/HDWZgX7.png)
3434

35+
- **Track Index** - The MIDI file track index that will be imported.
3536
- **BPM** - The importer doesn't support the BPM meta information, so that the
3637
BPM has to be set manually.
3738
- **Gate Easing** - When enabled, the note curves are to be smoothed by adding

0 commit comments

Comments
 (0)