Пример #1
0
        List <byte> process_track(byte[] data, uint songtrackdata_pointer, InstrumentMap instrument_map)
        {
            List <byte> ret = new List <byte>();

            //Transform the data.
            uint position   = songtrackdata_pointer;
            uint percussion = 0;

            while (true)
            {
                uint b = U.u8(data, position);
                position++;
                ret.Add((byte)b);

                if (b == 0xB1)
                {
                    break;
                }
                else if (b == 0xB2 || b == 0xB3)
                {
                    //repointer
                    U.append_u32(ret, U.p32(data, position) - songtrackdata_pointer);
                    position += 4;
                }
                else if (b == 0xBD)
                {
                    uint next_byte = U.u8(data, position);
                    position++;

                    uint translated = instrument_map.translate(next_byte);
                    if (translated == 0)
                    {
                        percussion = next_byte;
                    }
                    ret.Add((byte)translated);
                }
                else if (b == 0xBB || b == 0xBC || b == 0xBE || b == 0xBF || b == 0xC0 || b == 0xC1 || b == 0xC2 || b == 0xC3 || b == 0xC4 || b == 0xC5 || b == 0xC8)
                {
                    // These commands take a data byte that must not be processed.
                    ret.Add((byte)U.u8(data, position));
                    position++;
                }
                else if (b == 0xb9)
                {//MEMACC 4バイト命令
                    //最初の1バイトはコピー済みなので、残りの3バイトコピーする.
                    ret.Add((byte)U.u8(data, position));
                    position++;
                    ret.Add((byte)U.u8(data, position));
                    position++;
                    ret.Add((byte)U.u8(data, position));
                    position++;
                }
                else if (percussion != 0 && b < 0x80)
                {
                    uint inst = instrument_map.translate_percussion(percussion, b);
                    ret[ret.Count - 1] = ((byte)inst);
                    //There might be a volume marker, and then a 'gate' byte
                    //For now, assuming that any subsequent low-value bytes are extra data
                    //that should be passed as-is - even though previous experimentation suggested
                    //that these bytes could be used to specify a chord...
                    while (U.u8(data, position) < 0x80)
                    {// Volume marker
                        ret.Add((byte)U.u8(data, position));
                        position++;
                    }
                }
            }
            return(ret);
        }