Example #1
0
    public void ImportVGMFile(BinaryReader reader)
    {
        /*  TODO:
         *      Make sure that instrument editor is updated
         *      Make sure tracker controls are updated (specifically pattern length)
         */

        instruments.CreateInstrument();
        instruments.presets[0].volumeTable = new int[] { 0xF };
        instruments.presets[1].volumeTable = new int[] { 0xF };

        data.SetPatternLength(128);
        data.SetData(0, 0, 3, 0xf);
        data.SetData(0, 0, 4, 0x1);
        reader.BaseStream.Position = 0x40;
        data.currentPattern        = 0;
        m_LastVol = new int[4];

        bool eof = false;

        while (reader.BaseStream.Position < reader.BaseStream.Length && !eof)
        {
            byte cmd = reader.ReadByte();
            switch (cmd)
            {
            case 0x50:
                byte val = reader.ReadByte();
                ParsePSGData(val);
                break;

            case 0x61:
                int inc = Mathf.FloorToInt(reader.ReadUInt16() / 735.0f);
                m_CurrRow += inc;
                if (m_CurrRow >= data.patternLength)
                {
                    m_CurrRow -= data.patternLength;
                    data.AddPatternLine();
                }
                break;

            case 0x62:
            case 0x63:
                m_CurrRow++;
                if (m_CurrRow >= data.patternLength)
                {
                    m_CurrRow = 0;
                    data.AddPatternLine();
                }
                break;

            case 0x66:
                eof = true;
                break;
            }
        }

        matrix.UpdateMatrix();
        view.UpdatePatternData();
    }
    void OnGUI()
    {
        if (skin != null)
        {
            GUI.skin = skin;
        }

        Rect rect = new Rect(new Vector2(padding.x, padding.y), size);

        GUILayout.BeginArea(rect);
        GUILayout.BeginHorizontal( );
        GUILayout.BeginVertical(GUILayout.Width(24));
        if (GUILayout.Button("▲"))
        {
            data.MovePattern(-1);
        }
        if (GUILayout.Button("▼"))
        {
            data.MovePattern(1);
        }
        if (GUILayout.Button("+"))
        {
            data.AddPatternLine( );
        }
        if (GUILayout.Button("-"))
        {
            data.DeletePatternLine( );
        }
        if (GUILayout.Button("="))
        {
            data.CopyPatternLine( );
        }
        GUILayout.EndVertical( );

        Vector2 scroll = GUILayout.BeginScrollView(m_Scroll, false, true);

        if (!playback.isPlaying)
        {
            m_Scroll = scroll;
        }

        for (int i = 0; i < data.lookupTable.Count; i++)
        {
            GUILayout.BeginHorizontal();
            GUI.color = Color.blue;
            GUI.color = data.currentPattern == i ? selectedColor : neutralColor;
            for (int j = 0; j < data.channels; j++)
            {
                bool   ctrlDown = Input.GetKey(KeyCode.LeftControl);
                int    tableVal = ctrlDown ? data.transposeTable [i] [j] : data.lookupTable [i] [j];
                string label    = tableVal >= 0 ? tableVal.ToString("X2") : "X";
                if (ctrlDown)
                {
                    label = tableVal.ToString();
                }
                if (GUILayout.Button(label, GUILayout.Width(buttonSize.x), GUILayout.Height(buttonSize.y)) && !playback.isPlaying)
                {
                    if (data.currentPattern == i)
                    {
                        if (ctrlDown)
                        {
                            if (Input.GetMouseButtonUp(0))
                            {
                                data.transposeTable [i] [j]++;
                            }
                            else
                            {
                                data.transposeTable [i] [j]--;
                            }
                        }
                        else
                        {
                            int inc = 1;

                            if (Input.GetKey(KeyCode.LeftShift))
                            {
                                inc = 16;
                            }

                            if (Input.GetMouseButtonUp(0))
                            {
                                data.IncrementLookup(i, j, inc);
                            }
                            else
                            {
                                data.IncrementLookup(i, j, -inc);
                            }
                        }
                    }
                    else
                    {
                        data.currentPattern = i;
                    }
                }
            }
            GUILayout.EndHorizontal();
        }

        GUILayout.EndHorizontal();
        GUILayout.EndScrollView( );
        GUI.color = Color.white;
        if (GUILayout.Button("Optimize", GUILayout.Height(buttonSize.y)))
        {
            data.OptimizeSong( );
        }
        GUILayout.EndArea();
    }