/// <summary> /// Creates the midi track to add to the sequence. /// </summary> /// <param name="trackName"></param> /// <param name="instrument"></param> /// <param name="tempo"></param> /// <param name="time"></param> /// <param name="noteEvents"></param> /// <returns></returns> private static MidiTrack CreateTrack(string trackName, GeneralMidiInstrument instrument, int tempo, TimeSignature time, List <MidiEvent> noteEvents) { MidiTrack track = new MidiTrack(); MidiEventCollection events = track.Events; // Set the track name events.Add(SetTrackName(trackName)); // Set the instrument events.Add(SetInstrument(instrument)); // Set the tempo events.Add(SetTempo(tempo)); // Set the time signature events.Add(SetTimeSignature(time)); // add on off note events to track foreach (var note in noteEvents) { events.Add(note); } // Set the end of track flag events.Add(SetEndOfTrack()); return(track); }
public void SetInstrument(GeneralMidiInstrument instrument) { foreach (var staff in Score.Staves) { SetInstrument(staff, instrument); } }
/// <summary> /// The almighty constructor. Fear and respect the. /// </summary> /// <param name="trackName"></param> /// <param name="instrument"></param> /// <param name="tempo"></param> /// <param name="timeSignature"></param> /// <param name="noteCountToGenerate"></param> public RG(string trackName, GeneralMidiInstrument instrument, int tempo, TimeSignature timeSignature, int noteCountToGenerate) { _trackName = trackName; _instrument = instrument; _tempo = tempo; _timeSignature = timeSignature; _totalNotes = noteCountToGenerate; }
public IReadOnlyList <ChannelMessage> GetOrderedMessages(GeneralMidiInstrument inst, bool throwExceptionIfNotFound = false) { if (this.channelMessageByInstrument.ContainsKey(inst)) { return(this.channelMessageByInstrument[inst]); } if (throwExceptionIfNotFound) { throw new KeyNotFoundException(); } return(new List <ChannelMessage>().AsReadOnly()); }
public List <float> TicksPerQuarter(GeneralMidiInstrument inst, bool throwExceptionIfNotFound = false) { var messages = this.GetOrderedMessages(inst, throwExceptionIfNotFound); var meta = messages .Where(x => x.MidiMessage is MetaMessage) .Select(x => x.MidiMessage as MetaMessage) .Where(x => x.MetaType == MetaType.TimeSignature); var time = new TimeSignatureBuilder(); return(null); }
void SetInstrument(GeneralMidiInstrument gmInstrument) { if (midiSynth == null) { return; } ChannelMessageBuilder builder = new ChannelMessageBuilder(); builder.Command = ChannelCommand.ProgramChange; builder.MidiChannel = midiChannel; builder.Data1 = Convert.ToInt32(gmInstrument); // INSTRUMENT ID builder.Data2 = 0; builder.Build(); midiSynth.Send(builder.Result); }
/// <summary> /// Completely random. /// </summary> /// <param name="trackName"></param> /// <param name="amountToGenerate"></param> /// <returns></returns> public static MidiSequence Randomize(string trackName, int amountToGenerate, GeneralMidiInstrument instrument) { try { // create list of tracks List <MidiTrack> tracks = new List <MidiTrack>(); // randomized values for notes Random random = new Random(); // event list for on and off notes List <MidiEvent> events = new List <MidiEvent>(); for (int i = 0; i < amountToGenerate; i++) { // create the not and set the pitch and octave Note note = new Note(); note.Octave = random.Next(1, 8); note.Pitch = note.Pitches[random.Next(0, 11)]; note.Duration = note.Durations[random.Next(0, 13)]; // create the note on and off from properties inside class OnNoteVoiceMidiEvent on = note.CreateNoteOn(); OffNoteVoiceMidiEvent off = note.CreateNoteOff(); // add the events to the midievent list events.Add(on); events.Add(off); } // list of denoms int[] denominators = { 1, 2, 4, 8, 16, 32 }; // create track with the randomly generate midi events MidiTrack track = CreateTrack(trackName, instrument, random.Next(30, 300), new TimeSignature((byte)random.Next(1, 32), denominators[random.Next(0, 5)]), events); // add track to list tracks.Add(track); // create sequence MidiSequence midi = CreateSequence(tracks); return(midi); } catch (Exception) { throw; } }
public void SetInstrument(Staff staff, GeneralMidiInstrument instrument) { if (!Score.Staves.Contains(staff)) { throw new Exception($"Staff {staff} is not a part of the score associated with this player."); } var channel = GetChannelNumber(Score.Staves.IndexOf(staff)); for (var i = channel; i <= channel + 1; i++) { var builder = new ChannelMessageBuilder { MidiChannel = i, Data1 = (int)instrument, Command = ChannelCommand.ProgramChange }; builder.Build(); outDevice.Send(builder.Result); } }
public LaserToMidiAdapter(OutputDevice midiDevice, int midiChannel) { // set the midiChannel this.midiChannel = midiChannel; // selecte default instrument GeneralMidiInstrument currentInstrument = GeneralMidiInstrument.AcousticGrandPiano; // defining translation for laser to midi "note" laserToMidiTranslation.Add("A", 60); laserToMidiTranslation.Add("B", 62); laserToMidiTranslation.Add("C", 64); laserToMidiTranslation.Add("D", 66); laserToMidiTranslation.Add("E", 68); laserToMidiTranslation.Add("F", 70); laserToMidiTranslation.Add("G", 72); laserToMidiTranslation.Add("H", 74); laserToMidiTranslation.Add("I", 76); midiSynth = midiDevice; SetInstrument(currentInstrument); // set the instrument to use }
/// <summary>Initialize the ProgramChange MIDI event message.</summary> /// <param name="owner">The track that owns this event.</param> /// <param name="deltaTime">The delta-time since the previous message.</param> /// <param name="channel">The channel to which to write the message (0 through 15).</param> /// <param name="number">The instrument to which to change.</param> public ProgramChangeVoiceMidiEvent(MidiTrack owner, long deltaTime, byte channel, GeneralMidiInstrument number) : this(owner, deltaTime, channel, (byte)number) { }
internal ProgramChangeEvent(uint ticks, byte channel, GeneralMidiInstrument instrument) : base(ticks, channel) { this.instrument = instrument; }
/// <summary> /// Sets instrument. /// </summary> /// <param name="instrument"></param> /// <returns></returns> private ProgramChangeVoiceMidiEvent SetInstrument(GeneralMidiInstrument instrument) { return(new ProgramChangeVoiceMidiEvent(0, 0, instrument)); }
public IReadOnlyList<ChannelMessage> GetOrderedMessages(GeneralMidiInstrument inst, bool throwExceptionIfNotFound = false) { if (this.channelMessageByInstrument.ContainsKey(inst)) { return this.channelMessageByInstrument[inst]; } if (throwExceptionIfNotFound) { throw new KeyNotFoundException(); } return new List<ChannelMessage>().AsReadOnly(); }
public List<float> TicksPerQuarter(GeneralMidiInstrument inst, bool throwExceptionIfNotFound = false) { var messages = this.GetOrderedMessages(inst, throwExceptionIfNotFound); var meta = messages .Where(x => x.MidiMessage is MetaMessage) .Select(x => x.MidiMessage as MetaMessage) .Where(x => x.MetaType == MetaType.TimeSignature); var time = new TimeSignatureBuilder(); return null; }
public static MidiSequence Generate(List <int> allowableOctaves, List <int> allowablePitches, List <int> allowableDurations, string trackName, int amountToGenerate, GeneralMidiInstrument instrument, TimeSignature time, int tempo) { try { // create list of tracks List <MidiTrack> tracks = new List <MidiTrack>(); // randomized values for notes Random octaveRandom = new Random(); Random pitchRandom = new Random(); Random durationRandom = new Random(); // event list for on and off notes List <MidiEvent> events = new List <MidiEvent>(); for (int i = 0; i < amountToGenerate; i++) { // create the not and set the pitch and octave Note note = new Note(); note.Octave = allowableOctaves[octaveRandom.Next(0, allowableOctaves.Count)]; note.Pitch = note.Pitches[allowablePitches[pitchRandom.Next(0, allowablePitches.Count)]]; note.Duration = note.Durations[allowableDurations[durationRandom.Next(0, allowableDurations.Count)]]; // create the note on and off from properties inside class OnNoteVoiceMidiEvent on = note.CreateNoteOn(); OffNoteVoiceMidiEvent off = note.CreateNoteOff(); // add the events to the midievent list events.Add(on); events.Add(off); } // create track with the randomly generate midi events MidiTrack track = CreateTrack(trackName, instrument, tempo, time, events); // add track to list tracks.Add(track); // create sequence MidiSequence midi = CreateSequence(tracks); return(midi); } catch (Exception) { throw; } }
/// <summary> /// Sets instrument. /// </summary> /// <param name="instrument"></param> /// <returns></returns> public static ProgramChangeVoiceMidiEvent SetInstrument(GeneralMidiInstrument instrument) { return(new ProgramChangeVoiceMidiEvent(0, 0, instrument)); }
public ProgramChangeEvent(byte channel, GeneralMidiInstrument instrument) : this(0, channel, instrument) { }