コード例 #1
0
        public void Attack(IonianTone tone)
        {
            if (toneMap.ContainsKey(tone))
            {
                return;
            }

            var freq  = Scale.GetFrequency(tone);
            var index = Synthesizer.Attack(new Oscillator[] { new Oscillator(Wave.CurrentState, freq, OscillatorVolume) });

            toneMap[tone] = index;
        }
コード例 #2
0
        private void HandleEvent(MidiEvent e)
        {
            if (e is ChannelEvent channelEvent)
            {
                int  channel   = channelEvent.Channel;
                int  index     = MidiBuffer.Channels.IndexOf(channel);
                bool processed = false;
                switch (e)
                {
                case NoteOnEvent on:
                    if (sustainPedal && !sustains.Contains(index))
                    {
                        sustains.Add(index);
                    }
                    var freq = CalculateFrequency(on.NoteNumber);
                    foreach (var osc in OscillatorConfigs)
                    {
                        osc.Frequency = freq;
                    }
                    Synthesizer.Attack(OscillatorConfigs, index);
                    processed = true;
                    break;

                case NoteOffEvent off:
                    if (!sustainPedal)
                    {
                        Synthesizer.Release(index);
                    }
                    processed = true;
                    break;

                case ControlChangeEvent controlChange:
                    processed = HandleControlChange(controlChange);
                    break;
                }

                EventReceived?.Invoke(this, new MidiEventArgs(processed, e));
            }
        }