melanchall / drywetmidi

.NET library to read, write, process MIDI files and to work with MIDI devices
https://melanchall.github.io/drywetmidi
MIT License
540 stars 75 forks source link

CSharp Code Error #284

Closed Leonmmcoset closed 8 months ago

Leonmmcoset commented 8 months ago

Hello! This is my code: `using UnityEngine; using Melanchall.DryWetMidi.Core; using Melanchall.DryWetMidi.Interaction;

public class MidiPlayer : MonoBehaviour {

public TextAsset midiFile;

public KeyCode playKey = KeyCode.P;

public KeyCode stopKey = KeyCode.S;

public KeyCode repeatKey = KeyCode.R;
// MIDI播放器
private MidiFilePlayer midiPlayer;

void Start()
{

    midiPlayer = new MidiFilePlayer(midiFile.bytes);
}

void Update()
{

    if (Input.GetKeyDown(playKey))
    {
        PlayMidi();
    }

    if (Input.GetKeyDown(stopKey))
    {
        StopMidi();
    }

    if (Input.GetKeyDown(repeatKey))
    {
        ToggleRepeat();
    }
}

void PlayMidi()
{

    if (midiPlayer != null)
    {
        midiPlayer.Play();
    }
}

void StopMidi()
{

    if (midiPlayer != null)
    {
        midiPlayer.Stop();
    }
}

void ToggleRepeat()
{

    if (midiPlayer != null)
    {
        midiPlayer.Repeat = !midiPlayer.Repeat;
    }
}

}`

And has error:Assets\Code\Midi\MidiPlayer.cs(19,13): error CS0246: The type or namespace name 'MidiFilePlayer' could not be found (are you missing a using directive or an assembly reference?)

Please help me fix it!Thank you!

melanchall commented 8 months ago

Hi,

Your error means IDE doesn't know what MidiFilePlayer is. And I don't know too :-)

There is the complete API reference on the DryWetMIDI, where you can just type MidiFilePlayer in the search box and see there is no such class within the library. So I have no idea what this class is. But it's not related with DryWetMIDI.

You should talk with the author of the code because if you don't know what MidiFilePlayer is, it's probably not your code.

Thanks, Max

Leonmmcoset commented 8 months ago

Thank you