コード例 #1
0
 public void NewInstrument()
 {
     instruments.CreateInstrument( );
     UpdateEnvelopes();
     view.UpdatePatternData();
     UpdateInstruments();
     SetSelectedInstrument(instruments.presets.Length - 1);
 }
コード例 #2
0
    public void SetSelectedRow(MatrixRow select)
    {
        if (selection != null)
        {
            selection.SetSelected(false);
        }

        if (select != null)
        {
            select.SetSelected(true);
            selection = select;
        }

        if (playback.isPlaying && selection != null)
        {
            if (!scrollRect.viewport.rect.Contains(selection.transform.localPosition + scrollRect.content.localPosition))
            {
                Vector3 pos = scrollRect.content.localPosition;
                pos.y = -selection.transform.localPosition.y - 150;
                scrollRect.content.localPosition = pos;
            }
        }

        patternView.UpdatePatternData();
    }
コード例 #3
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();
    }
コード例 #4
0
    void Update()
    {
        if (!ExclusiveFocus.currentFocus && Input.GetKeyDown(KeyCode.Return))
        {
            if (m_IsPlaying)
            {
                Stop();
            }
            else
            {
                Play(true);
            }
        }

        if (follow && m_IsPlaying && Time.time - m_LastLineTick > 1f / 50f)
        {
            while (m_MoveLine > 0)
            {
                m_MoveLine--;

                if (m_PatternBreakTarget >= 0)
                {
                    data.currentPattern++;
                    view.selectedLine    = m_PatternBreakTarget;
                    m_PatternBreakTarget = -1;

                    view.UpdatePatternData();
                    continue;
                }

                view.selectedLine++;
                if (view.selectedLine == 0)
                {
                    data.currentPattern++;
                    if (data.currentPattern >= data.numPatterns)
                    {
                        data.currentPattern = m_PatternLoop;
                    }

                    view.UpdatePatternData( );
                }

                m_LastLineTick = Time.time;
            }
        }
    }
コード例 #5
0
    private void ApplyEvent(FiniteStack <HistoryEvent> apply)
    {
        if (apply.count <= 0)
        {
            return;
        }

        HistoryEvent next = apply.Pop();

        next.Restore(data.songData);
        data.currentPattern = next.pattern;
        view.UpdatePatternData();
        Debug.Log("Next line is " + next.position.line);
        view.SetSelection(next.position);
    }
コード例 #6
0
ファイル: SongData.cs プロジェクト: N-SPC700/SnoozeTracker
    public void OptimizeSong()
    {
        if (!TinyFileDialogs.MessageBox("Optimizing song", "This will erase any unused patterns! Are you sure?", TinyFileDialogs.DialogType.YESNO, TinyFileDialogs.IconType.WARNING, false))
        {
            return;
        }

        Dictionary <int, int> sortedIndicies = new Dictionary <int, int> ( );
        List <ColumnEntry>    sortedData     = new List <ColumnEntry> ( );

        foreach (int[] row in m_LookupTable)
        {
            for (int i = 0; i < 4; i++)
            {
                int oldIndex = row [i];
                int newIndex = sortedData.Count;

                if (oldIndex >= 0 && !sortedIndicies.ContainsKey(oldIndex))
                {
                    sortedData.Add(m_SongData [row [i]]);
                    sortedIndicies.Add(oldIndex, newIndex);
                }
            }
        }

        foreach (int [] row in m_LookupTable)
        {
            for (int i = 0; i < 4; i++)
            {
                if (sortedIndicies.ContainsKey(row [i]))
                {
                    row [i] = sortedIndicies [row [i]];
                }
            }
        }

        m_SongData = sortedData;
        patternMatrix.UpdateMatrix();
        patternView.UpdatePatternData();
    }
コード例 #7
0
    public void OpenFile()
    {
        if (fileModified && !TinyFileDialogs.MessageBox("Opening tune", "Are you sure? You will lose all unsaved progress.", TinyFileDialogs.DialogType.YESNO, TinyFileDialogs.IconType.WARNING, false))
        {
            return;
        }

        playback.Stop( );
        data.currentPattern = 0;

        if (m_TuneOpen.ShowDialog())
        {
            IFormatter formatter = new BinaryFormatter( );
            Stream     fs        = m_TuneOpen.OpenFile( );

            SongFile open = (SongFile)formatter.Deserialize(fs);
            fs.Close( );

            if (!open.success)
            {
                return;
            }

            data.SetPatternLength(open.patternLength);
            data.lookupTable = open.lookupTable;
            if (open.transposeTable != null && open.transposeTable.Count == open.lookupTable.Count)
            {
                data.transposeTable = open.transposeTable;
            }
            else
            {
                Debug.Log("Transpose table too shourt!!");
                data.transposeTable = new List <int []> ( );
                for (int i = 0; i < data.lookupTable.Count; i++)
                {
                    int [] transposeEntry;

                    if (open.transposeTable != null && i < open.transposeTable.Count)
                    {
                        transposeEntry = open.transposeTable [i];
                    }
                    else
                    {
                        transposeEntry = new int [data.channels];
                    }

                    data.transposeTable.Add(transposeEntry);
                }
            }
            data.songData = open.songData;

            SongData.songName   = open.songName ?? "";
            SongData.artistName = open.artistName ?? "";

            keyboard.currentInstrument = 0;

            int presetCount = open.instruments.Length;
            Array.Resize(ref instruments.presets, presetCount);
            Array.Copy(open.instruments, instruments.presets, presetCount);

            m_OpenFile   = m_TuneOpen.filePath;
            fileModified = false;

            if (onFileOpen != null)
            {
                onFileOpen( );
            }

            patternMatrix.UpdateMatrix();
            patternView.UpdatePatternData();
            insEditor.UpdateInstruments();
            insEditor.UpdateInstrumentInfo();
            insEditor.SetSelectedInstrument(0);
            playback.playbackSpeed = 6;
        }
    }