NScumm.Core.Audio.SoftSynth.TownsMidiInputChannel.NoteOn C# (CSharp) Method

NoteOn() public method

public NoteOn ( byte note, byte velocity ) : void
note byte
velocity byte
return void
        public override void NoteOn(byte note, byte velocity)
        {
            TownsMidiOutputChannel oc = _driver.AllocateOutputChannel(_priority);

            if (oc == null)
                return;

            oc.Connect(this);

            oc._adjustModTl = (byte)(_instrument[10] & 1);
            oc._note = note;
            oc._sustainNoteOff = 0;
            oc._duration = (short)(_instrument[29] * 63);

            oc._operator1Tl = (byte)((_instrument[1] & 0x3f) + _driver._operatorLevelTable[((velocity >> 1) << 5) + (_instrument[4] >> 2)]);
            if (oc._operator1Tl > 63)
                oc._operator1Tl = 63;

            oc._operator2Tl = (byte)((_instrument[6] & 0x3f) + _driver._operatorLevelTable[((velocity >> 1) << 5) + (_instrument[9] >> 2)]);
            if (oc._operator2Tl > 63)
                oc._operator2Tl = 63;

            oc.SetupProgram(_instrument, oc._adjustModTl == 1 ? _programAdjustLevel[_driver._operatorLevelTable[(_tl >> 2) + (oc._operator1Tl << 5)]] : oc._operator1Tl, _programAdjustLevel[_driver._operatorLevelTable[(_tl >> 2) + (oc._operator2Tl << 5)]]);
            oc.NoteOn((byte)(note + _transpose), _freqLSB);

            if ((_instrument[11] & 0x80) != 0)
                oc.SetupEffects(0, _instrument[11], _instrument, 12);
            else
                oc._effectEnvelopes[0].state = EnvelopeState.Ready;

            if ((_instrument[20] & 0x80) != 0)
                oc.SetupEffects(1, _instrument[20], _instrument, 21);
            else
                oc._effectEnvelopes[1].state = EnvelopeState.Ready;
        }

Usage Example

Example #1
0
        public override void Send(int b)
        {
            if (!_isOpen)
            {
                return;
            }

            int  param2 = ((b >> 16) & 0xFF);
            byte param1 = (byte)((b >> 8) & 0xFF);
            byte cmd    = (byte)(b & 0xF0);

            TownsMidiInputChannel c = _channels[b & 0x0F];

            switch (cmd)
            {
            case 0x80:
                c.NoteOff(param1);
                break;

            case 0x90:
                if (param2 != 0)
                {
                    c.NoteOn(param1, (byte)param2);
                }
                else
                {
                    c.NoteOff(param1);
                }
                break;

            case 0xB0:
                c.ControlChange(param1, (byte)param2);
                break;

            case 0xC0:
                c.ProgramChange(param1);
                break;

            case 0xE0:
                c.PitchBend((short)((param1 | (param2 << 7)) - 0x2000));
                break;

            case 0xF0:
                Debug.WriteLine("MidiDriver_TOWNS: Receiving SysEx command on a send() call");
                break;
            }
        }