Exemple #1
0
        private void OnGenerateOJNListMenuClick(object sender, EventArgs e)
        {
            var saveDialog = new SaveFileDialog();

            saveDialog.FileName = "OJNList";
            saveDialog.Filter   = "O2Jam Music List|*.dat";

            if (saveDialog.ShowDialog() == DialogResult.OK)
            {
                LoadingForm loader = null;
                loader = new LoadingForm(async() =>
                {
                    try
                    {
                        using (var stream = new FileStream(saveDialog.FileName, FileMode.Create, FileAccess.ReadWrite))
                            using (var writer = new BinaryWriter(stream))
                            {
                                int count = 0;
                                stream.Seek(4, SeekOrigin.Begin);
                                await Task.Run(() =>
                                {
                                    foreach (var chart in charts)
                                    {
                                        try
                                        {
                                            loader.SetStatus(string.Format("Processing {0} - {1}..", Path.GetFileName(chart.Filename), chart.Title));
                                            loader.SetProgress(((float)count / charts.Count) * 100f);

                                            if (File.Exists(chart.Filename))
                                            {
                                                var header = File.ReadAllBytes(chart.Filename).Take(300);
                                                writer.Write(header.ToArray());
                                                count++;
                                            }
                                        }
                                        finally
                                        {
                                        }
                                    }
                                });

                                loader.SetStatus("Finalizing..");
                                loader.SetProgress(100f);

                                stream.Seek(0, SeekOrigin.Begin);
                                writer.Write(count);
                            }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        loader.DialogResult = DialogResult.Abort;
                    }
                    finally
                    {
                        loader.Close();
                    }
                });

                if (loader.ShowDialog() != DialogResult.Abort)
                {
                    MessageBox.Show("OJNList has been saved successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Exemple #2
0
        private void AddChart(string[] filenames)
        {
            bool initial = MusicList.Items.Count == 0;
            var  err     = new List <string>();

            MusicList.BeginUpdate();
            {
                LoadingForm loader = null;
                loader = new LoadingForm(async() =>
                {
                    float progress = 0;
                    foreach (string filename in filenames)
                    {
                        Chart chart = null;
                        try
                        {
                            if (charts.FirstOrDefault((existing) => existing.Filename == filename) == null)
                            {
                                chart = await ChartDecoder.DecodeHeaderAsync(filename, (int)OJN.Difficulty.HX);
                                charts.Add(chart);

                                var item = new ListViewItem(new string[] {
                                    chart.Title,
                                    chart.Artist,
                                    chart.Pattern,
                                    chart.Duration.ToString(@"mm\:ss")
                                });

                                MusicList.Items.Add(item);
                            }
                        }
                        catch (Exception ex)
                        {
                            err.Add(string.Format("{0}: {1}", Path.GetFileName(filename), ex.Message));
                        }

                        progress++;
                        if (loader.IsHandleCreated)
                        {
                            loader.SetStatus(string.Format("Processing {0} - {1}", Path.GetFileName(filename), chart?.Title));
                            loader.SetProgress((progress / filenames.Length) * 100f);
                        }
                    }

                    loader.Close();
                });

                loader.ShowDialog();
                if (MusicList.ListViewItemSorter == null)
                {
                    var listSorter = new ListViewColumnSorter();
                    listSorter.Order = SortOrder.Ascending;

                    MusicList.ListViewItemSorter = listSorter;
                }

                var sorter      = MusicList.ListViewItemSorter as ListViewColumnSorter;
                var chartSorter = new ChartSorter();
                chartSorter.SortType = (ChartSortType)sorter.SortColumn;
                chartSorter.Order    = sorter.Order;

                MusicList.Sort();
                charts?.Sort(chartSorter);
            }
            MusicList.EndUpdate();

            if (err.Count > 0)
            {
                string errfn = "";
                foreach (string fn in err)
                {
                    errfn += fn + Environment.NewLine;
                }

                MessageBox.Show("Failed to decode following charts: " + Environment.NewLine + errfn, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (charts.Count > 0 && initial)
            {
                playback.Track = 0;
                GenerateOJNListMenu.Enabled   = SavePlaylistMenu.Enabled =
                    RenderMenu.Enabled        = OpenMenu.Enabled =
                        GroupPlayback.Enabled = PlaybackMenu.Enabled = true;
            }
        }
Exemple #3
0
        private void OnStartButtonClick(object sender, EventArgs e)
        {
            string filename  = "";
            string directory = "";
            string err       = "";

            int format  = FormatSelector.SelectedIndex;
            int freq    = int.Parse(FrequencySelector.SelectedItem.ToString().Split(' ').First());
            int channel = StereoRadio.Checked ? 2 : 1;

            if (charts.Length == 1)
            {
                var saveDialog = new SaveFileDialog();
                saveDialog.FileName = string.Format("{0} - {1}", charts[0].Artist, charts[0].Title);

                if (format == 0)
                {
                    saveDialog.FileName += ".mp3";
                    saveDialog.Filter    = "MP3 - MPEG-1 Audio Layer 3|*.mp3";
                }
                else if (format == 1)
                {
                    saveDialog.FileName += ".ogg";
                    saveDialog.Filter    = "OGG - Vorbis Audio|*.ogg";
                }
                else
                {
                    saveDialog.FileName += ".wav";
                    saveDialog.Filter    = "WAV - Waveform Audio|*.wav";
                }

                if (saveDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                filename = saveDialog.FileName;
            }
            else if (charts.Length > 1)
            {
                var browserDialog = new FolderBrowserDialog();
                browserDialog.ShowNewFolderButton = true;

                if (browserDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                directory = browserDialog.SelectedPath;
            }

            LoadingForm loader = null;

            loader = new LoadingForm(async() =>
            {
                float progress = 0;
                loader.SetStatus("Initializing..");

                foreach (var chart in charts)
                {
                    try
                    {
                        loader.SetStatus(string.Format("Prerendering {0}..", chart.Title));

                        var fullChart = await ChartDecoder.DecodeAsync(chart.Filename, 2);
                        var data      = await Prerender(fullChart, format, channel, freq);

                        if (charts.Length == 1)
                        {
                            File.WriteAllBytes(filename, data);
                        }
                        else if (charts.Length > 1)
                        {
                            filename = string.Format("{0} - {1}", chart.Artist, chart.Title);
                            if (format == 0)
                            {
                                filename += ".mp3";
                            }
                            else if (format == 1)
                            {
                                filename += ".ogg";
                            }
                            else
                            {
                                filename += ".wav";
                            }

                            filename = string.Format("{0}{1}{2}",
                                                     directory,
                                                     Path.DirectorySeparatorChar,
                                                     filename
                                                     );

                            File.WriteAllBytes(filename, data);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (charts.Length == 1)
                        {
                            err = ex.Message;
                            loader.DialogResult = DialogResult.Cancel;
                            loader.Close();
                        }
                    }
                    finally
                    {
                        progress++;
                        loader.SetProgress((progress / charts.Length) * 100f);
                    }
                }

                loader.Close();
            });

            if (loader.ShowDialog() == DialogResult.Abort)
            {
                if (charts.Length == 1)
                {
                    MessageBox.Show("Failed to prerender the chart into file\n." + err, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (!string.IsNullOrEmpty(directory))
                {
                    MessageBox.Show("Failed to render following charts:\n." + err, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
            else
            {
                MessageBox.Show("Prerender has been completed successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            Close();
        }