Esempio n. 1
0
 /// <summary>
 /// Инициализирует новый объект типа MidiNoteEventArgs с заданными параметрами.
 /// </summary>
 /// <param name="noteNo"></param>
 /// <param name="velocity"></param>
 /// <param name="pressedNotesCount"></param>
 public MidiNoteEventArgs(byte noteNo, byte velocity, int pressedNotesCount)
 {
     Note = new MidiNote {
         NoteNo = noteNo, Velocity = velocity
     };
     PressedNotesCount = pressedNotesCount;
 }
Esempio n. 2
0
        /// <summary>
        /// Играет переданную ноту.
        /// </summary>
        /// <param name="note">Нота, которую необходимо проиграть.</param>
        public void PlayNote(MidiNote note)
        {
            Voice voice;

            if (freeVoicesIndices.Count == 0)
            {
                voice = activeVoices[0];
                StopVoice(voice);
            }
            else
            {
                voice = voicesPool[freeVoicesIndices.Min];
            }

            byte noteNo = note.NoteNo;

            if (!noteToVoicesMapping.ContainsKey(noteNo))
            {
                noteToVoicesMapping[noteNo] = new List <Voice>();
            }

            noteToVoicesMapping[noteNo].Add(voice);
            activeVoices.Add(voice);
            freeVoicesIndices.Remove(voicesPool.IndexOf(voice));
            voice.PlayNote(note);
        }
Esempio n. 3
0
        /// <summary>
        /// Отпускает переданную ноту.
        /// </summary>
        /// <param name="note">Нота, которую необходимо отпустить.</param>
        public void ReleaseNote(MidiNote note)
        {
            byte noteNo = note.NoteNo;

            if (noteToVoicesMapping.ContainsKey(noteNo))
            {
                foreach (var voice in noteToVoicesMapping[noteNo])
                {
                    voice.TriggerRelease();
                }
            }
        }