Ejemplo n.º 1
0
        static void LoadRhythm(Adlib0 adlib, int cmfChannel, Cmf.Instrument instrument)
        {
            int i, j;

            switch (cmfChannel)
            {
            case 11:     // bassdrum
                i = 16;
                j = 19;
                adlib.Poke(0x20 + i, instrument.iModChar);
                adlib.Poke(0x40 + i, instrument.iModScale);
                adlib.Poke(0x60 + i, instrument.iModAttack);
                adlib.Poke(0x80 + i, instrument.iModSustain);
                adlib.Poke(0xE0 + i, instrument.iModWaveSel);
                adlib.Poke(0x20 + j, instrument.iCarChar);
                adlib.Poke(0x40 + j, instrument.iCarScale);
                adlib.Poke(0x60 + j, instrument.iCarAttack);
                adlib.Poke(0x80 + j, instrument.iCarSustain);
                adlib.Poke(0xE0 + j, instrument.iCarWaveSel);
                adlib.Poke(0xC0 + 6, instrument.iFeedback);

                break;

            case 12:     // snare
                i = 20;
                adlib.Poke(0x20 + i, instrument.iModChar);
                adlib.Poke(0x40 + i, instrument.iModScale);
                adlib.Poke(0x60 + i, instrument.iModAttack);
                adlib.Poke(0x80 + i, instrument.iModSustain);
                adlib.Poke(0xE0 + i, instrument.iModWaveSel);
                adlib.Poke(0xC0 + 7, instrument.iFeedback);
                break;

            case 13:     // tom
                i = 18;
                adlib.Poke(0x20 + i, instrument.iModChar);
                adlib.Poke(0x40 + i, instrument.iModScale);
                adlib.Poke(0x60 + i, instrument.iModAttack);
                adlib.Poke(0x80 + i, instrument.iModSustain);
                adlib.Poke(0xE0 + i, instrument.iModWaveSel);
                adlib.Poke(0xC0 + 8, instrument.iFeedback);
                break;

            case 14:     // cymbal
                i = 21;
                adlib.Poke(0x20 + i, instrument.iModChar);
                adlib.Poke(0x40 + i, instrument.iModScale);
                adlib.Poke(0x60 + i, instrument.iModAttack);
                adlib.Poke(0x80 + i, instrument.iModSustain);
                adlib.Poke(0xE0 + i, instrument.iModWaveSel);
                adlib.Poke(0xC0 + 8, instrument.iFeedback);
                break;

            case 15:     // hihat
                i = 17;
                adlib.Poke(0x20 + i, instrument.iModChar);
                adlib.Poke(0x40 + i, instrument.iModScale);
                adlib.Poke(0x60 + i, instrument.iModAttack);
                adlib.Poke(0x80 + i, instrument.iModSustain);
                adlib.Poke(0xE0 + i, instrument.iModWaveSel);
                adlib.Poke(0xC0 + 7, instrument.iFeedback);
                break;
            }
        }
Ejemplo n.º 2
0
        void Dispatch(MidiEvent ev)
        {
            switch (miv.type)
            {
            case MidiEvent.Type.Controller:
                switch (ev.p1)
                {
                case 0x63:         // depth control
                                   // TD: implement
                    break;

                case 0x66:         // song marker
                                   // This can be used to notify the music player that a certain point
                                   // in a song has been reached, or to trigger some kind of action in
                                   // time with the music.
                    break;

                case 0x67:         // control rhythm mode
                    rhythmMode = ev.p2 > 0;

                    if (rhythmMode)
                    {
                        regbd = 1 << 5;
                        adlib.Poke(0xBD, regbd);
                    }
                    else
                    {
                        regbd = 0;
                        adlib.Poke(0xBD, regbd);
                    }
                    break;

                case 0x68:         // transpose up
                                   // TD: implement
                    break;

                case 0x69:         // transpose down
                                   // TD: implement
                    break;
                }
                break;

            case MidiEvent.Type.ProgramChange:
                if (rhythmMode && ev.channel >= 11)
                {
                    LoadRhythm(adlib, ev.channel, cmfFile.instruments[ev.p1]);
                }
                else
                {
                    LoadInstrument(adlib, ev.channel, cmfFile.instruments[ev.p1]);
                }
                break;

            case MidiEvent.Type.NoteOn:
                if (ev.p2 > 0)
                {
                    if (channels[ev.channel].midiNote != -1)
                    {
                        SetGate(ev.channel, false);
                    }

                    channels[ev.channel].midiNote = ev.p1;


                    if (rhythmMode && ev.channel >= 11)
                    {
                        if (ev.channel == 11)    // bassdrum
                        {
                            SetChannelPitch(6, ev.p1);
                        }

                        SetRhythmGate(ev.channel, true);
                        SetRhythmVelocity(ev.channel, ev.p2 / 127f);

                        switch (ev.channel)
                        {
                        case 11:         // bassdrum
                            ChannelActivity?.Invoke(time, 6, ev.p2 / 127f);
                            break;

                        case 12:         // snare
                        case 13:         // tom
                            ChannelActivity?.Invoke(time, 7, ev.p2 / 127f);
                            break;

                        case 14:         // cymbal
                        case 15:         // hat
                            ChannelActivity?.Invoke(time, 8, ev.p2 / 127f);
                            break;
                        }
                    }
                    else
                    {
                        SetChannelPitch(ev.channel, ev.p1);
                        SetChannelVelocity(ev.channel, ev.p2 / 127f);
                        SetGate(ev.channel, true);

                        ChannelActivity?.Invoke(time, ev.channel, ev.p2 / 127f);
                    }
                }
                else
                {
                    if (channels[ev.channel].midiNote == ev.p1)
                    {
                        channels[ev.channel].midiNote = -1;

                        if (rhythmMode && ev.channel >= 11)
                        {
                            SetRhythmGate(ev.channel, false);
                        }
                        else
                        {
                            SetGate(ev.channel, false);
                        }
                    }
                }
                break;

            case MidiEvent.Type.NoteOff:
                if (channels[ev.channel].midiNote == ev.p1)
                {
                    if (rhythmMode && ev.channel >= 11)
                    {
                        SetRhythmGate(ev.channel, false);
                    }
                    else
                    {
                        SetGate(ev.channel, false);
                    }
                }
                break;
            }
        }
Ejemplo n.º 3
0
        static void LoadInstrument(Adlib0 adlib, int channel, Cmf.Instrument instrument)
        {
            var optbl = new int[] { 0, 1, 2, 8, 9, 10, 16, 17, 18 };

            adlib.Poke(0x20 + optbl[channel], instrument.iModChar);
            adlib.Poke(0x23 + optbl[channel], instrument.iCarChar);
            adlib.Poke(0x40 + optbl[channel], instrument.iModScale);
            adlib.Poke(0x43 + optbl[channel], instrument.iCarScale);
            adlib.Poke(0x60 + optbl[channel], instrument.iModAttack);
            adlib.Poke(0x63 + optbl[channel], instrument.iCarAttack);
            adlib.Poke(0x80 + optbl[channel], instrument.iModSustain);
            adlib.Poke(0x83 + optbl[channel], instrument.iCarSustain);
            adlib.Poke(0xE0 + optbl[channel], instrument.iModWaveSel);
            adlib.Poke(0xE3 + optbl[channel], instrument.iCarWaveSel);
            adlib.Poke(0xC0 + channel, instrument.iFeedback);
        }