Exemple #1
0
    public void ZapSong()
    {
        if (!TinyFileDialogs.MessageBox("Nuking song!", "This will erase the entire song. All unsaved progress will be lost!", TinyFileDialogs.DialogType.OKCANCEL, TinyFileDialogs.IconType.WARNING, false))
        {
            return;
        }

        patternView.playback.playbackSpeed = 6;
        UnityEngine.SceneManagement.SceneManager.LoadScene(0);
    }
Exemple #2
0
    public void ImportVGM()
    {
        if (fileModified && !TinyFileDialogs.MessageBox("Importing VGM",
                                                        "Are you sure? You will lose all unsaved progress.", TinyFileDialogs.DialogType.YESNO,
                                                        TinyFileDialogs.IconType.WARNING, false))
        {
            return;
        }

        if (m_VgmImport.ShowDialog())
        {
            BinaryReader br = new BinaryReader(m_VgmImport.OpenFile( ));
            vgmImport.ImportVGMFile(br);
        }
    }
        public SongFile(SerializationInfo info, StreamingContext context)
        {
            fileVersion = -1;
            success     = true;
            foreach (SerializationEntry e in info)
            {
                switch (e.Name)
                {
                case "version":
                    fileVersion = ( int )e.Value;

                    if (fileVersion > CURRENT_VERSION)
                    {
                        TinyFileDialogs.MessageBox("Incompatible file version!",
                                                   "Trying to open file saved by a newer version!\n" +
                                                   "(File version: " + fileVersion + ")",
                                                   TinyFileDialogs.DialogType.OK, TinyFileDialogs.IconType.ERROR, true);
                        success = false;
                        return;
                    }
                    break;

                case "songName": songName = ( string )e.Value; break;

                case "artistName": artistName = (string)e.Value; break;

                case "patternLength": patternLength = ( int )e.Value; break;

                case "lookupTable": lookupTable = (List <int []>)e.Value; break;

                case "transposeTable": transposeTable = (List <int []>)e.Value; break;

                case "songData": songData = (List <SongData.ColumnEntry>)e.Value; break;

                case "instruments":
                    if (fileVersion < CURRENT_VERSION)
                    {
                        instrumentsLegacy = (List <Instruments.InstrumentInstance>)info.GetValue("instruments", typeof(List <Instruments.InstrumentInstance>));
                    }
                    else
                    {
                        instruments = (Instruments.InstrumentInstance [])e.Value;
                    }
                    break;
                }
            }
        }
Exemple #4
0
    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();
    }
    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;
        }
    }