public GamePlayer(InputDevice input, MidiFile midifile, MidiOptions midiOption) { inputDevice = input; processer = new MidiProcesser(midifile, midiOption); inputDevice.NoteOn += delegate(NoteOnMessage msg) { ComputeScore(msg.Pitch, processer.Position); }; inputDevice.NoteOff += delegate(NoteOffMessage msg) { }; inputDevice.ProgramChange += delegate(ProgramChangeMessage msg) { }; inputDevice.PitchBend += delegate(PitchBendMessage msg) { }; }
public void OutDeviceTest() { ReadOnlyCollection<OutputDevice> devices = OutputDevice.InstalledDevices; if (devices.Count == 0) { Console.WriteLine("No out put devices"); return; } foreach (OutputDevice device in devices) { Console.WriteLine(" OutputDevices Name:"+ device.Name); } MidiFile midiFile = new MidiFile("E:/13.mid"); MidiOptions options = new MidiOptions(midiFile); MidiPlayer player = new MidiPlayer(midiFile, options); foreach (OutputDevice device in devices) { if (device.IsMidiPort) { player.OutDevice = device; } } if (player.OutDevice == null) { player.OutDevice = devices[0]; } player.Start(); }
public LearningPlayer(InputDevice input, MidiFile midifile, MidiOptions midiOption) { processer = new MidiProcesser(midifile, midiOption); inputDevice = input; inputDevice.NoteOn += delegate(NoteOnMessage msg) { ProcessPitch(msg.Pitch); }; processer.NoteOn += delegate(Channel channel, Pitch pitch, int velocity) { waitPitch = pitch; processer.Stop(); }; }
public bool useDefaultInstruments; /** If true, don't change instruments */ #endregion Fields #region Constructors public MidiOptions(MidiFile midifile) { int numtracks = midifile.Tracks.Count; tracks = new bool[numtracks]; mute = new bool[numtracks]; instruments = new int[numtracks]; for (int i = 0; i < tracks.Length; i++) { tracks[i] = true; mute[i] = false; instruments[i] = midifile.Tracks[i].Instrument; if (midifile.Tracks[i].InstrumentName == "Percussion") { tracks[i] = false; } } useDefaultInstruments = true; scrollVert = true; largeNoteSize = false; if (tracks.Length == 1) { twoStaffs = true; } else { twoStaffs = false; } showNoteLetters = NoteNameNone; showLyrics = true; showMeasures = false; shifttime = 0; transpose = 0; key = -1; time = midifile.Time; colors = null; shadeColor = Color.FromArgb(210, 205, 220); shade2Color = Color.FromArgb(80, 100, 250); combineInterval = 40; tempo = midifile.Time.Tempo; pauseTime = 0; playMeasuresInLoop = false; playMeasuresInLoopStart = 0; playMeasuresInLoopEnd = midifile.EndTime() / midifile.Time.Measure; }
public MidiPlayer(MidiFile midiFile, MidiOptions midiOptions) { processer = new MidiProcesser(midiFile, midiOptions); processer.NoteOn += delegate(Channel channel, Pitch pitch, int velocity) { if (outDevice != null) { outDevice.SendNoteOn(channel,pitch,velocity); } }; processer.NoteOff += delegate(Channel channel, Pitch pitch, int velocity) { if (outDevice != null) { outDevice.SendNoteOff(channel, pitch, velocity); } }; processer.ProgramChange += delegate(Channel channel, Instrument instrument) { if (outDevice != null) { outDevice.SendProgramChange(channel, instrument); } }; processer.ControlChange += delegate(Channel channel, MidiControl control, int value) { if (outDevice != null) { outDevice.SendControlChange(channel, control,value); } }; }
public void TestScore() { MidiFile midiFile = new MidiFile("E:/14.mid"); MidiOptions options = new MidiOptions(midiFile); ReadOnlyCollection<InputDevice> devices = InputDevice.InstalledDevices; if (devices.Count == 0) { Console.WriteLine("No input devices"); return; } ReadOnlyCollection<OutputDevice> outDevices = OutputDevice.InstalledDevices; if (outDevices.Count == 0) { Console.WriteLine("No out put devices"); return; } OutputDevice outDevice = outDevices[1]; if (outDevice != null && !outDevice.IsOpen) { outDevice.Open(); } foreach (InputDevice device in devices) { if (!device.IsOpen) { device.Open(); device.StartReceiving(new Clock(10)); } device.NoteOn += delegate(NoteOnMessage msg) { Console.WriteLine("NoteOnMessage => Pitch :"+msg.Pitch+"clock:"+msg.Time); }; device.NoteOff += delegate(NoteOffMessage msg) { Console.WriteLine("NoteOffMessage => Pitch :" + msg.Pitch); }; device.ProgramChange += delegate(ProgramChangeMessage msg) { Console.WriteLine("ProgramChangeMessage => Ins :" + msg.Instrument); }; device.PitchBend += delegate(PitchBendMessage msg) { Console.WriteLine("PitchBendMessage => Pitch :" + msg.Value); }; GamePlayer player = new GamePlayer(device, midiFile, options); player.StartPlayer(); player.PlayEvent += delegate(GamePlayer.State state, int score, MidiEvent[] events) { Console.WriteLine("state:" + state + " score:" + score); }; } }
/* Command-line program to print out a parsed Midi file. Used for debugging. * To run: * - Change Main2 to Main * - csc MidiNote.cs MidiEvent.cs MidiTrack.cs MidiFileReader.cs MidiOptions.cs * MidiFile.cs MidiException.cs TimeSignature.cs * - MidiFile.exe file.mid * */ public static void Main2(string[] arg) { if (arg.Length == 0) { Console.WriteLine("Usage: MidiFile <filename>"); return; } MidiFile f = new MidiFile(arg[0]); Console.Write(f.ToString()); }