public override bool Equals(object obj) { if (obj is NoteRegistryKey) { NoteRegistryKey r = (NoteRegistryKey)obj; return(r.channel == this.channel && r.note == this.note); } return(false); }
public void NoteOff(int channel, int note) { NoteRegistryKey r = new NoteRegistryKey((byte)channel, (byte)note); List<Voice> voice; if (keyRegistry.TryGetValue(r, out voice)) { if (voice.Count > 0) { voice[0].Stop(); voice.RemoveAt(0); } } }
public void NoteOff(int channel, int note) { NoteRegistryKey r = new NoteRegistryKey((byte)channel, (byte)note); List <Voice> voice; if (keyRegistry.TryGetValue(r, out voice)) { if (voice.Count > 0) { voice[0].Stop(); voice.RemoveAt(0); } } }
public void NoteOffAll(int channel, int note) { NoteRegistryKey r = new NoteRegistryKey((byte)channel, (byte)note); if (keyRegistry.TryGetValue(r, out List <Voice> voices)) { foreach (Voice v in voices) { v.Stop(); } voices.Clear(); } }
public void NoteOn(int channel, int note, int velocity, int program) { // Grab a free voice Voice freeVoice = getFreeVoice(); if (freeVoice == null) { // If there are no free voices steal an active one. freeVoice = getUsedVoice(activeVoices.First.Value.getKey()); // If there are no voices to steal then leave this method. if (freeVoice == null) { return; } } // Create a key for this event NoteRegistryKey r = new NoteRegistryKey((byte)channel, (byte)note); // Get the correct instrument depending if it is a drum or not if (channel == 9) { freeVoice.setInstrument(bank.getInstrument(program, true)); } else { freeVoice.setInstrument(bank.getInstrument(program, false)); } // Check if key exists if (keyRegistry.ContainsKey(r)) { if (keyRegistry[r].Count >= maxnotepoly) { keyRegistry[r][0].Stop(); keyRegistry[r].RemoveAt(0); } keyRegistry[r].Add(freeVoice); } else//The first noteOn of it's own type will create a list for multiple occurences { List <Voice> Vlist = new List <Voice>(maxnotepoly); Vlist.Add(freeVoice); keyRegistry.Add(r, Vlist); } freeVoice.Start(channel, note, velocity); activeVoices.AddLast(freeVoice); }
private Voice getUsedVoice(NoteRegistryKey r) { List <Voice> voicelist; Voice voice; if (keyRegistry.TryGetValue(r, out voicelist)) { if (voicelist.Count > 0) { voicelist[0].StopImmediately(); voice = voicelist[0]; voicelist.RemoveAt(0); activeVoices.Remove(voice); return(voice); } } return(null); }
public void NoteOn(int channel, int note, int velocity, int program) { // Grab a free voice Voice freeVoice = getFreeVoice(); if (freeVoice == null) { // If there are no free voices steal an active one. freeVoice = getUsedVoice(activeVoices.First.Value.getKey()); // If there are no voices to steal then leave this method. if (freeVoice == null) return; } // Create a key for this event NoteRegistryKey r = new NoteRegistryKey((byte)channel, (byte)note); // Get the correct instrument depending if it is a drum or not if (channel == 9) freeVoice.setInstrument(bank.getInstrument(program, true)); else freeVoice.setInstrument(bank.getInstrument(program, false)); //Check if key already exists in registry if (keyRegistry.ContainsKey(r)) {//If there are too many of these notes playing then stop the first of them before playing another if (keyRegistry[r].Count >= maxnotepoly) { keyRegistry[r][0].Stop(); keyRegistry[r].RemoveAt(0); } keyRegistry[r].Add(freeVoice); } else//The first noteOn of it's own type will create a list for multiple occurences { List<Voice> Vlist = new List<Voice>(maxnotepoly); Vlist.Add(freeVoice); keyRegistry.Add(r, Vlist); } freeVoice.Start(channel, note, velocity); activeVoices.AddLast(freeVoice); }
private Voice getUsedVoice(NoteRegistryKey r) { List<Voice> voicelist; Voice voice; if (keyRegistry.TryGetValue(r, out voicelist)) { if (voicelist.Count > 0) { voicelist[0].StopImmediately(); voice = voicelist[0]; voicelist.RemoveAt(0); activeVoices.Remove(voice); return voice; } } return null; }
public bool Equals(NoteRegistryKey obj) { return(obj.channel == this.channel && obj.note == this.note); }
public bool Equals(NoteRegistryKey obj) { return obj.channel == this.channel && obj.note == this.note; }