예제 #1
0
        void ImportGBAWave(NumericUpDown addrNumObj)
        {
            uint addr = (uint)addrNumObj.Value;

            addr = U.toOffset(addr);

            if (AddressList.SelectedIndex < 0)
            {
                return;
            }
            uint songtable_address = InputFormRef.BaseAddress + (InputFormRef.BlockSize * (uint)AddressList.SelectedIndex);

            string title  = R._("インポートするwavファイルを選択してください");
            string filter = R._("wav|*.wav|All files|*");

            OpenFileDialog open = new OpenFileDialog();

            open.Title  = title;
            open.Filter = filter;
            Program.LastSelectedFilename.Load(this, "", open);
            DialogResult dr = open.ShowDialog();

            if (dr != DialogResult.OK)
            {
                return;
            }
            if (!U.CanReadFileRetry(open))
            {
                return;
            }
            Program.LastSelectedFilename.Save(this, "", open);
            string filename = open.FileNames[0];

            SongInstrumentImportWaveForm f = (SongInstrumentImportWaveForm)InputFormRef.JumpFormLow <SongInstrumentImportWaveForm>();

            f.Init(filename);
            dr = f.ShowDialog();
            if (dr != System.Windows.Forms.DialogResult.OK)
            {
                f.Dettach();
                return;
            }
            byte[] wave    = File.ReadAllBytes(f.GetFilename());
            byte[] gbawave = SongUtil.wavToByte(wave);
            if (gbawave == null)
            {
                return;
            }

            f.Dettach();

            Undo.UndoData undodata = Program.Undo.NewUndoData(this, "Instrument Wave");
            uint          newaddr  = InputFormRef.WriteBinaryData(this, addr, gbawave, gbawave_length, undodata);

            Program.Undo.Push(undodata);

            addrNumObj.Value = newaddr;
            WriteButton.PerformClick();
        }