public virtual Interactor.Base CreateInteractor(TrackPlayer tp, ChannelMessage cm) { EPointF ptLoc = new EPointF(); int note = cm.Data1; int strength = cm.Data2; int duration = 10; Interactor.Base interactor = null; LocSetter.Base locSetter = null; Endogine.Node node = this._trackSettings[tp.Track.Name]; if (node != null) { if (node["Interactor"]!=null) { string sType = "MusicGame.Midi.Interactor."+node["Interactor"].Text; Type type = Type.GetType(sType); System.Reflection.ConstructorInfo cons = type.GetConstructor(new Type[]{}); interactor = (Interactor.Base)cons.Invoke(new object[]{}); } if (node["LocSetter"]!=null) { string sType = "MusicGame.Midi.LocSetter." + node["LocSetter"].Text; Type type = Type.GetType(sType); System.Reflection.ConstructorInfo cons = type.GetConstructor(new Type[]{}); locSetter = (LocSetter.Base)cons.Invoke(new object[]{}); } } if (interactor==null) interactor = new Interactor.Default(); // if (locSetter==null) // locSetter = new LocSetter.Default(); interactor.Prepare(tp.Track.Name, cm.MidiChannel, this._readAheadMsecs, note, strength, duration, ptLoc); if (locSetter!=null) locSetter.Parent = interactor; this._spritesToStart.Add(interactor); return interactor; }
/// <summary> /// Visits channel messages. /// </summary> /// <param name="message"> /// The channel message to visit. /// </param> public override void Visit(ChannelMessage message) { // If the running status does not match the message's status value. if(message.Status != runningStatus) { // Keep track of new running status. runningStatus = message.Status; // Write status value. midiStream.WriteByte((byte)message.Status); } // Write the first data value. midiStream.WriteByte((byte)message.Data1); // The the channel message uses two data values. if(ChannelMessage.BytesPerType(message.Command) > 1) { // Write the second data value. midiStream.WriteByte((byte)message.Data2); } }
/// <summary> /// /// </summary> /// <param name="message"></param> public virtual void Visit(ChannelMessage message) { }
/// <summary> /// Reads the next channel message. /// </summary> /// <param name="status"> /// The status value for the next channel message. /// </param> /// <param name="data1"> /// The first data byte. /// </param> /// <returns> /// The next channel message. /// </returns> private ChannelMessage ReadChannelMessage(int status, int data1) { ChannelMessage msg; ChannelCommand command = (ChannelCommand)(status & ChannelMask); int channel = status & ~ChannelMask; // If this is a channel message that has two data bytes. if(command != ChannelCommand.ChannelPressure && command != ChannelCommand.ProgramChange) { // Get second data byte. int data2 = binReader.ReadByte(); // Create channel message. msg = new ChannelMessage(command, channel, data1, data2); } // Else this channel message only has one data byte. else { // Create channel message. msg = new ChannelMessage(command, channel, data1); } return msg; }
/// <summary> /// Initializes the MIDI chaser. /// </summary> private void Initialize() { channelPressureMessage = null; polyPressureMessage = null; programChangeMessage = null; pitchBendMessage = null; for(int i = 0; i < controllers.Length; i++) { controllers[i] = null; } tempoChangeMessage = null; }
/// <summary> /// Visits channel messages. /// </summary> /// <param name="message"> /// The channel message to visit. /// </param> /// <remarks> /// This method should not be called by an outside source. /// </remarks> public override void Visit(ChannelMessage message) { if(message.Command == ChannelCommand.ChannelPressure) { channelPressureMessage = message; } else if(message.Command == ChannelCommand.PolyPressure) { polyPressureMessage = message; } else if(message.Command == ChannelCommand.ProgramChange) { programChangeMessage = message; } else if(message.Command == ChannelCommand.PitchWheel) { pitchBendMessage = message; } else if(message.Command == ChannelCommand.Controller) { controllers[message.Data1] = message; } }
/// <summary> /// Sends a channel message. /// </summary> /// <param name="message"> /// The message to send. /// </param> /// <remarks> /// This method filters messages based on the state of the track. /// </remarks> private void Send(ChannelMessage message) { if(mute) return; else if(soloModeEnabled && !solo) return; else this.SendMessage(message); //this._midiSender.Send(message); }
/// <summary> /// Visit channel messages. /// </summary> /// <param name="message"> /// The channel message to visit. /// </param> public override void Visit(ChannelMessage message) { // If this is a note-on message. if(message.Command == ChannelCommand.NoteOn) { // If the velocity is greater than zero, keep track of message. // This message turns a note on. if(message.Data2 > 0) { noteOnTable[message.Data1] = message; } // Else the velocity is zero, treat this note-on message as a // note off message. else { // Indicate that this note is not currently playing. noteOnTable[message.Data1] = null; } // Send with filtering. Send(message); } // Else if this is a note-off message. else if(message.Command == ChannelCommand.NoteOff) { // Indicate that this note is note currently playing. noteOnTable[message.Data1] = null; // Send with filtering. Send(message); } // Else if this is a controller message. else if(message.Command == ChannelCommand.Controller) { // If this is a hold pedal message. if(message.Data1 == (int)ControllerType.HoldPedal) { // If the hold pedal is on, indicate that the hold pedal // is on. if(message.Data2 >= HoldPedalOnValue) holdPedalMessage = message; // Else the hold pedal is off, indicate that it is off. else holdPedalMessage = null; } // Send message without filtering. //this._midiSender.Send(message); this.SendMessage(message); } // Else this is another type of MIDI message. else { // Send message without filtering. this.SendMessage(message); //this._midiSender.Send(message); } }
/// <summary> /// Turns all currently sounding notes off. /// </summary> /// <remarks> /// When a track is muted, all of the currently sounding notes need to /// be turned off. Also, a sequencer can call this method if one of the /// other tracks are soloed. /// </remarks> public void AllSoundsOff() { ChannelMessage message; // If the hold pedal is currently on, turn it off. if(holdPedalMessage != null) { message = new ChannelMessage(ChannelCommand.Controller, holdPedalMessage.MidiChannel, holdPedalMessage.Data1, 0); //this._midiSender.Send(message); this.SendMessage(message); } // Created channel message for turning notes off. message = new ChannelMessage(ChannelCommand.NoteOff, 0, 0, 0); // Iterate through the note-on table turning off any currently // turned on notes. for(int i = 0; i < ShortMessage.DataValueMax; i++) { // If the note has been turned on, turn it off. if(noteOnTable[i] != null) { message.MidiChannel = noteOnTable[i].MidiChannel; message.Data1 = noteOnTable[i].Data1; //this._midiSender.Send(message); this.SendMessage(message); } } holdPedalMessage = null; ResetNoteOnTable(); }
/// <summary> /// Initializes a new instance of the ChannelMessageEventArgs class with the /// specified ChannelMessage and time stamp. /// </summary> /// <param name="message"> /// The ChannelMessage for this event. /// </param> /// <param name="timeStamp"> /// The time in milliseconds since the input device began recording. /// </param> public ChannelMessageEventArgs(ChannelMessage message, int timeStamp) { this.message = message; this.timeStamp = timeStamp; }
/// <summary> /// Initializes a new instance of the ChannelMessage class with /// another instance of the ChannelMessage class. /// </summary> /// <param name="message"> /// The ChannelMessage instance to use for initialization. /// </param> public ChannelMessage(ChannelMessage message) { Command = message.Command; MidiChannel = message.MidiChannel; Data1 = message.Data1; Data2 = message.Data2; }
/// <summary> /// Sends a channel message. /// </summary> /// <param name="message"> /// The channel message to send. /// </param> /// <exception cref="OutputDeviceException"> /// Thrown if an error occurred while sending the message. /// </exception> public void Send(ChannelMessage message) { // Guard. if(!IsOpen()) return; // If running status is enabled. if(runningStatusEnabled) { // If running status matches the status value of the message. if(runningStatus == message.Status) { // Remove status value. int msg = message.Message >> StatusShift; // Send message without status value. ThrowOnError(midiOutShortMsg(handle, msg)); } // Else the running status does not match the status value of // the message. else { // Send message with status value. ThrowOnError(midiOutShortMsg(handle, message.Message)); // Update running status. runningStatus = message.Status; } } }
/// <summary> /// Determines the type of message received and triggers the correct /// event in response. /// </summary> /// <param name="message"> /// The short Midi message received. /// </param> /// <param name="timeStamp"> /// Number of milliseconds that have passed since the input device /// began recording. /// </param> private void DispatchShortMessage(int message, int timeStamp) { // Unpack status value. int status = ShortMessage.UnpackStatus(message); // If a channel message was received. if(ChannelMessage.IsChannelMessage(status)) { // If anyone is listening for channel messages. if(ChannelMessageReceived != null) { // Create channel message. ChannelMessage msg = new ChannelMessage(message); // Create channel message event argument. ChannelMessageEventArgs e = new ChannelMessageEventArgs(msg, timeStamp); // Trigger channel message received event. ChannelMessageReceived(this, e); } } // Else if a system common message was received else if(SysCommonMessage.IsSysCommonMessage(status)) { // If anyone is listening for system common messages if(SysCommonReceived != null) { // Create system common message. SysCommonMessage msg = new SysCommonMessage(message); // Create system common event argument. SysCommonEventArgs e = new SysCommonEventArgs(msg, timeStamp); // Trigger system common received event. SysCommonReceived(this, e); } } // Else if a system realtime message was received else if(SysRealtimeMessage.IsSysRealtimeMessage(status)) { // If anyone is listening for system realtime messages if(SysRealtimeReceived != null) { // Create system realtime message. SysRealtimeMessage msg = new SysRealtimeMessage(message); // Create system realtime event argument. SysRealtimeEventArgs e = new SysRealtimeEventArgs(msg, timeStamp); // Trigger system realtime received event. SysRealtimeReceived(this, e); } } }