MidiSheetMusic.MidiFile.ApplyOptionsPerChannel C# (CSharp) Method

ApplyOptionsPerChannel() private method

private ApplyOptionsPerChannel ( MidiOptions options ) : List[]
options MidiOptions
return List[]
        private List<MidiEvent>[] ApplyOptionsPerChannel(MidiOptions options)
        {
            /* Determine which channels to include/exclude.
             * Also, determine the instruments for each channel.
             */
            int[] instruments = new int[16];
            bool[] keepchannel = new bool[16];
            for (int i = 0; i < 16; i++) {
            instruments[i] = 0;
            keepchannel[i] = true;
            }
            for (int tracknum = 0; tracknum < tracks.Count; tracknum++) {
            MidiTrack track = tracks[tracknum];
            int channel = track.Notes[0].Channel;
            instruments[channel] = options.instruments[tracknum];
            if (options.tracks[tracknum] == false ||
                options.mute[tracknum] == true) {

                keepchannel[channel] = false;
            }
            }

            List<MidiEvent>[] newevents = CloneMidiEvents(events);

            /* Set the tempo at the beginning of each track */
            for (int tracknum = 0; tracknum < newevents.Length; tracknum++) {
            MidiEvent mevent = CreateTempoEvent(options.tempo);
            newevents[tracknum].Insert(0, mevent);
            }

            /* Change the note number (transpose), instrument, and tempo */
            for (int tracknum = 0; tracknum < newevents.Length; tracknum++) {
            foreach (MidiEvent mevent in newevents[tracknum]) {
                int num = mevent.Notenumber + options.transpose;
                if (num < 0)
                    num = 0;
                if (num > 127)
                    num = 127;
                mevent.Notenumber = (byte)num;
                if (!keepchannel[mevent.Channel]) {
                    mevent.Velocity = 0;
                }
                if (!options.useDefaultInstruments) {
                    mevent.Instrument = (byte)instruments[mevent.Channel];
                }
                mevent.Tempo = options.tempo;
            }
            }
            if (options.pauseTime != 0) {
            newevents = StartAtPauseTime(newevents, options.pauseTime);
            }
            return newevents;
        }