コード例 #1
0
        private void MenuSongsCreate_Click(object sender, EventArgs e)
        {
            SongData   song = new SongData(Storage);
            FormatData data = new TemporaryFormatData(song, Storage);

            if (EditForm.Show(data, true, true, this) != DialogResult.Cancel)
            {
                Progress.QueueTask(progress => {
                    progress.NewTask("Installing \"" + data.Song.Name + "\" locally", 2);

                    FormatData localdata = PlatformLocalStorage.Instance.CreateSong(Storage, data.Song);
                    data.SaveTo(localdata);
                    data.Dispose();
                    progress.Progress();

                    PlatformLocalStorage.Instance.SaveSong(Storage, localdata, progress);
                    progress.Progress();

                    UpdateSongList();
                    progress.EndTask();
                });
            }
            else
            {
                data.Dispose();
            }
        }
コード例 #2
0
        private void ReplaceAudioButton_Click(object sender, EventArgs e)
        {
            OpenDialog.Multiselect = true;
            OpenDialog.Title       = "Select audio files";
            OpenDialog.Filter      = "Common Audio Files|*.ogg;*.wav;*.flac;*.mp3;*.aiff;*.ac3|All Files|*";
            if (OpenDialog.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            bool allogg = true;

            using (DelayedStreamCache cache = new DelayedStreamCache()) {
                FormatData    data    = new TemporaryFormatData();
                AudioFormat   format  = new AudioFormat();
                List <string> names   = new List <string>();
                Stream[]      streams = new Stream[OpenDialog.FileNames.Length];
                for (int i = 0; i < streams.Length; i++)
                {
                    string filename = OpenDialog.FileNames[i];
                    streams[i] = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);

                    cache.AddStream(streams[i]);
                    IDecoder decoder;
                    if (new EndianReader(streams[i], Endianness.BigEndian).ReadUInt32() != OggMagic)
                    {
                        allogg = false;
                        streams[i].Position = 0;
                        decoder             = new FFmpegDecoder(streams[i]);
                    }
                    else
                    {
                        decoder = new RawkAudio.Decoder(streams[i], RawkAudio.Decoder.AudioFormat.VorbisOgg);
                    }

                    for (int k = 0; k < decoder.Channels; k++)
                    {
                        names.Add(Path.GetFileName(filename) + " [Channel #" + (k + 1).ToString("0") + "]");
                        float balance = 0;
                        if (decoder.Channels == 2)
                        {
                            balance = k == 0 ? -1 : 1;
                        }
                        format.Mappings.Add(new AudioFormat.Mapping(0, balance, Platform.InstrumentFromString(Path.GetFileNameWithoutExtension(filename))));
                    }

                    decoder.Dispose();
                    streams[i].Position = 0;
                }

                if (AudioForm.Show(format, names.ToArray(), this) == DialogResult.Cancel)
                {
                    return;
                }

                foreach (IFormat audioformat in Data.GetFormats(FormatType.Audio))
                {
                    foreach (string audiostream in Data.GetStreamNames(audioformat))
                    {
                        Data.DeleteStream(audiostream);
                    }
                }

                if (allogg)
                {
                    AudioFormatOgg.Instance.Create(data, streams, format);
                }
                else
                {
                    AudioFormatFFmpeg.Instance.Create(data, streams, format);
                }
                data.SaveTo(Data);
            }

            UpdateAudioSizes();
        }
コード例 #3
0
        private void ReplaceChartButton_Click(object sender, EventArgs e)
        {
            OpenDialog.Multiselect = false;
            OpenDialog.Title       = "Select a note chart file";
            OpenDialog.Filter      = "Supported Files (*.mid, *.chart)|*.mid;*.chart|All Files|*";
            if (OpenDialog.ShowDialog(this) == DialogResult.Cancel)
            {
                return;
            }

            Stream stream = new FileStream(OpenDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            Mid    mid    = Mid.Create(stream);

            stream.Position = 0;
            Chart chart = mid == null?Chart.Create(stream) : null;

            if (mid == null && chart == null)
            {
                stream.Close();
                throw new FormatException();
            }

            List <IChartFormat> formats = new List <IChartFormat>();

            if (mid != null)
            {
                formats.Add(ChartFormatRB.Instance);
                formats.Add(ChartFormatGH2.Instance);
            }
            if (chart != null)
            {
                formats.Add(ChartFormatChart.Instance);
            }

            ChartForm.ShowResult result = ChartForm.Show(formats, this);
            if (result.Result == DialogResult.Cancel)
            {
                return;
            }

            if (mid != null || chart != null)
            {
                foreach (IFormat format in Data.GetFormats(FormatType.Chart))
                {
                    foreach (string chartstream in Data.GetStreamNames(format))
                    {
                        Data.DeleteStream(chartstream);
                    }
                }
            }

            Stream milo    = null;
            Stream pan     = null;
            Stream weights = null;

            FormatData data = new TemporaryFormatData(Data.Song);

            if (result.Format == ChartFormatRB.Instance)
            {
                if (result.Milo.HasValue())
                {
                    milo = new FileStream(result.Milo, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
                if (result.Weights.HasValue())
                {
                    weights = new FileStream(result.Weights, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
                if (result.Pan.HasValue())
                {
                    pan = new FileStream(result.Pan, FileMode.Open, FileAccess.Read, FileShare.Read);
                }

                ChartFormatRB.Instance.Create(data, stream, pan, weights, milo, result.ExpertPlus, result.FixForQuickplay, Song.Game);
            }
            else if (result.Format == ChartFormatGH2.Instance)
            {
                ChartFormatGH2.Instance.Create(data, stream, result.Coop);
            }
            else if (result.Format == ChartFormatChart.Instance)
            {
                ChartFormatChart.Instance.Create(data, stream, result.Coop);
            }

            data.SaveTo(Data);

            stream.Close();

            if (milo != null)
            {
                milo.Close();
            }
            if (pan != null)
            {
                pan.Close();
            }
            if (weights != null)
            {
                weights.Close();
            }

            UpdateChartSizes();
        }