Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MIDI file track selection #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Assets/MidiAnim/Editor/MidiAnimImporter.cs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ namespace MidiAnim
[ScriptedImporter(1, "midianim")]
class MidiAnimImporter : ScriptedImporter
{
[SerializeField] int _trackIndex = 0;
[SerializeField] float _bpm = 120;
[SerializeField] bool _gateEasing = false;
[SerializeField] float _attackTime = 0.1f;
@@ -20,7 +21,7 @@ class MidiAnimImporter : ScriptedImporter
public override void OnImportAsset(AssetImportContext context)
{
var song = MidiFileLoader.Load(File.ReadAllBytes(context.assetPath));
var seq = new MidiTrackSequencer(song.tracks[0], song.division, _bpm);
var seq = new MidiTrackSequencer(song.tracks[_trackIndex], song.division, _bpm);

var clip = new MidiClip(_bpm);
if (_gateEasing) clip.EnableEasing(_attackTime, _releaseTime);
4 changes: 4 additions & 0 deletions Assets/MidiAnim/Editor/MidiAnimImporterEditor.cs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -12,13 +12,15 @@ namespace MidiAnim
[CustomEditor(typeof(MidiAnimImporter))]
class MidiAnimImporterEditor : ScriptedImporterEditor
{
SerializedProperty _trackIndex;
SerializedProperty _bpm;
SerializedProperty _gateEasing;
SerializedProperty _attackTime;
SerializedProperty _releaseTime;

static class Styles
{
public static readonly GUIContent TrackIndex = new GUIContent("Track Index");
public static readonly GUIContent BPM = new GUIContent("BPM");
}

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

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

public override void OnInspectorGUI()
{
EditorGUILayout.PropertyField(_trackIndex, Styles.TrackIndex);
EditorGUILayout.PropertyField(_bpm, Styles.BPM);
EditorGUILayout.PropertyField(_gateEasing);

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@ There are a few settings in the inspector.

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

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