Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public FormYMF262Editor(YMF262 inst, YMF262Timbre timbre, bool singleSelect) : base(inst, timbre, singleSelect)
        {
            this.timbre = timbre;
            InitializeComponent();

            Size = Settings.Default.YMF262EdSize;

            var gen = new YMF262GeneralContainer(inst, timbre, "General");

            AddControl(gen);

            AddControl(new YMF262OperatorContainer(timbre.Ops[0], null, "Operator 1"));
            AddControl(new YMF262OperatorContainer(timbre.Ops[1], null, "Operator 2"));
            AddControl(new YMF262OperatorContainer(timbre.Ops[2], gen, "Operator 3"));
            AddControl(new YMF262OperatorContainer(timbre.Ops[3], gen, "Operator 4"));
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="provider"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;

            if (provider != null)
            {
                editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
            }

            if (editorService == null)
            {
                return(value);
            }

            bool         singleSel = true;
            YMF262Timbre tim       = context.Instance as YMF262Timbre;

            YMF262Timbre[] tims = value as YMF262Timbre[];
            if (tims != null)
            {
                tim       = tims[0];
                singleSel = false;
            }

            YMF262 inst = null;

            try
            {
                //InstrumentManager.ExclusiveLockObject.EnterReadLock();

                inst = InstrumentManager.FindParentInstrument(InstrumentType.YMF262, tim) as YMF262;
            }
            finally
            {
                //InstrumentManager.ExclusiveLockObject.ExitReadLock();
            }

            if (inst != null)
            {
                if (singleSel)
                {
                    var mmlValueGeneral = SimpleSerializer.SerializeProps(tim,
                                                                          nameof(tim.ALG),
                                                                          nameof(tim.FB),
                                                                          nameof(tim.FB2),
                                                                          "GlobalSettings.EN",
                                                                          "GlobalSettings.DAM",
                                                                          "GlobalSettings.DVB"
                                                                          );
                    var consel = inst.CONSEL;
                    inst.CONSEL = 6;

                    List <string> mmlValueOps = new List <string>();
                    for (int i = 0; i < tim.Ops.Length; i++)
                    {
                        var op = tim.Ops[i];
                        mmlValueOps.Add(SimpleSerializer.SerializeProps(op,
                                                                        nameof(op.AR),
                                                                        nameof(op.DR),
                                                                        nameof(op.RR),
                                                                        nameof(op.SL),
                                                                        nameof(op.SR),
                                                                        nameof(op.TL),
                                                                        nameof(op.KSL),
                                                                        nameof(op.KSR),
                                                                        nameof(op.MFM),
                                                                        nameof(op.AM),
                                                                        nameof(op.VIB),
                                                                        nameof(op.EG),
                                                                        nameof(op.WS)
                                                                        ));
                    }
                    FormYMF262Editor ed = new FormYMF262Editor(inst, tim, singleSel);
                    {
                        ed.MmlValueGeneral = mmlValueGeneral;

                        ed.FormClosed += (s, e) =>
                        {
                            inst.CONSEL = consel;
                            if (ed.DialogResult == DialogResult.OK)
                            {
                                if (consel == 0 && ((YMF262Timbre)ed.Timbre).ALG >= 2)
                                {
                                    MessageBox.Show(Resources.CNTWarning, "Warning", MessageBoxButtons.OK);
                                }

                                tim.Detailed = ed.MmlValueGeneral + "," + ed.MmlValueOps[0] + "," + ed.MmlValueOps[1] + "," + ed.MmlValueOps[2] + "," + ed.MmlValueOps[3];
                            }
                            else if (ed.DialogResult == DialogResult.Cancel)
                            {
                                tim.Detailed = mmlValueGeneral + "," + mmlValueOps[0] + "," + mmlValueOps[1] + "," + mmlValueOps[2] + "," + mmlValueOps[3];
                            }
                        };
                        ed.Show();
                        ed.Activated += (s, e) =>
                        {
                            if (consel == 0 && ((YMF262Timbre)ed.Timbre).ALG >= 2)
                            {
                                MessageBox.Show(Resources.CNTWarning, "Warning", MessageBoxButtons.OK);
                            }

                            tim.Detailed = ed.MmlValueGeneral + "," + ed.MmlValueOps[0] + "," + ed.MmlValueOps[1] + "," + ed.MmlValueOps[2] + "," + ed.MmlValueOps[3];
                        };
                    }
                }
                else
                {
                    using (FormYMF262Editor ed = new FormYMF262Editor(inst, tim, singleSel))
                    {
                        string org    = JsonConvert.SerializeObject(tims, Formatting.Indented);
                        var    consel = inst.CONSEL;
                        inst.CONSEL = 6;
                        DialogResult dr = editorService.ShowDialog(ed);
                        inst.CONSEL = consel;
                        if (dr == DialogResult.OK || dr == DialogResult.Abort)
                        {
                            if (consel == 0 && ((YMF262Timbre)ed.Timbre).ALG >= 2)
                            {
                                MessageBox.Show(Resources.CNTWarning, "Warning", MessageBoxButtons.OK);
                            }
                            return(value);
                        }
                        else
                        {
                            return(JsonConvert.DeserializeObject <YMF262Timbre[]>(org));
                        }
                    }
                }
            }

            return(value);                   // エディタ呼び出し直前の設定値をそのまま返す
        }
Exemplo n.º 3
0
        public override IEnumerable <Tone> ImportToneFile(string fileName)
        {
            string      ext    = System.IO.Path.GetExtension(fileName);
            var         Option = new Option();
            List <Tone> tones  = new List <Tone>();

            try
            {
                switch (ext.ToUpper(CultureInfo.InvariantCulture))
                {
                case ".WOPL":
                {
                    using (var file = new System.IO.BinaryReader(new System.IO.FileStream(fileName, System.IO.FileMode.Open)))
                    {
                        file.BaseStream.Seek(0x11, System.IO.SeekOrigin.Begin);
                        {
                            var val = file.ReadByte();
                            //if ((val & 1) != 0)
                            //    tone.AMD = 1;
                            //if ((val & 2) != 0)
                            //    tone.VIB = 1;
                        }

                        file.BaseStream.Seek(0x57, System.IO.SeekOrigin.Begin);
                        for (int i = 0; i < 128; i++)
                        {
                            Tone tone1 = new Tone();
                            Tone tone2 = new Tone();
                            tone1.Number = i * 2;
                            tone2.Number = i * 2 + 1;

                            //32
                            var name = Encoding.ASCII.GetString(file.ReadBytes(32));
                            var nidx = name.IndexOf('\0');
                            if (nidx >= 0)
                            {
                                name = name.Substring(0, nidx);
                            }
                            if (name != null && name.Length != 0)
                            {
                                tone1.Name = name;
                                tone2.Name = name + "(2nd)";
                            }
                            //2
                            tone1.KeyShift = YMF262.ReadInt16Big(file);
                            //2
                            tone2.KeyShift = YMF262.ReadInt16Big(file);

                            //1
                            file.ReadByte();            //MIDI Velocity offset
                            //1
                            tone2.PitchShift = file.ReadSByte();

                            //1
                            //DrumTimbres[i].BaseNote = (NoteNames)file.ReadByte();
                            file.ReadByte();
                            //1
                            var opmode = file.ReadByte();

                            if (opmode == 0)                //2OP
                            {
                                setRegisters(file, tone1, null);
                                tones.Add(tone1);
                            }
                            else if (opmode == 1)           //4OP
                            {
                                setRegisters(file, tone1, tone2);
                                tone1.CNT    = (tone1.CNT << 1 | tone2.CNT) + 2;
                                tone1.FB2    = tone2.FB;
                                tone1.aOp[2] = tone2.aOp[0];
                                tone1.aOp[3] = tone2.aOp[1];
                                tones.Add(tone1);
                            }
                            else if (opmode == 3)
                            {
                                setRegisters(file, tone1, tone2);
                                tones.Add(tone1);
                                tones.Add(tone2);
                            }
                            else if ((opmode & 4) == 4)
                            {
                                //empty
                            }
                            else
                            {
                                // System.Windows.Forms.MessageBox.Show("Unsupported op mode " + opmode);
                            }
                        }

                        for (int i = 0; i < 128; i++)
                        {
                            Tone tone1 = new Tone();
                            Tone tone2 = new Tone();
                            tone1.Number = i * 2 + 256;
                            tone2.Number = i * 2 + 256 + 1;

                            //32
                            var name = Encoding.ASCII.GetString(file.ReadBytes(32));
                            var nidx = name.IndexOf('\0');
                            if (nidx >= 0)
                            {
                                name = name.Substring(0, nidx);
                            }
                            if (name != null && name.Length != 0)
                            {
                                tone1.Name = name;
                                tone2.Name = name + "(2nd)";
                            }
                            else
                            {
                                tone1.Name = tone1.Number.ToString();
                                tone2.Name = tone2.Number.ToString();
                            }

                            //2
                            tone1.KeyShift = ReadInt16Big(file);
                            //2
                            tone2.KeyShift = ReadInt16Big(file);

                            //1
                            file.ReadByte();            //MIDI Velocity offset
                            //1
                            tone2.PitchShift = file.ReadSByte();

                            //1
                            //TODO: Drum
                            //DrumTimbres[i].BaseNote = (NoteNames)file.ReadByte();
                            file.ReadByte();
                            //1
                            var opmode = file.ReadByte();

                            if (opmode == 0)                //2OP
                            {
                                setRegisters(file, tone1, null);
                                tones.Add(tone1);
                            }
                            else if (opmode == 1)           //4OP
                            {
                                setRegisters(file, tone1, tone2);
                                tone1.CNT    = (tone1.CNT << 1 | tone2.CNT) + 2;
                                tone1.aOp[2] = tone2.aOp[0];
                                tone1.aOp[3] = tone2.aOp[1];
                                tones.Add(tone1);
                            }
                            else if (opmode == 3)
                            {
                                setRegisters(file, tone1, tone2);
                                tones.Add(tone1);
                                tones.Add(tone2);
                            }
                            else if ((opmode & 4) == 4)
                            {
                                //empty
                            }
                            else
                            {
                                // System.Windows.Forms.MessageBox.Show("Unsupported op mode " + opmode);
                            }
                        }
                    }
                }
                break;

                case ".OPL":
                {
                    List <Head> list          = new List <Head>();
                    byte        maxBankNumber = 0;

                    using (var file = new System.IO.BinaryReader(new System.IO.FileStream(fileName, System.IO.FileMode.Open)))
                    {
                        while (true)
                        {
                            //read head
                            Head p = new Head();
                            p.Patch  = file.ReadByte();
                            p.Bank   = file.ReadByte();
                            p.Offset = file.ReadUInt32();

                            if (p.Patch == 0xff && p.Bank == 0xff)
                            {
                                break;
                            }

                            if ((p.Bank != 0x7F) && (p.Bank > maxBankNumber))
                            {
                                maxBankNumber = p.Bank;
                            }

                            list.Add(p);
                        }
                        ;

                        for (int i = 0; i < list.Count; i++)
                        {
                            var p = list[i];
                            file.BaseStream.Seek(p.Offset, System.IO.SeekOrigin.Begin);

                            bool isPerc    = (p.Bank == 0x7F);
                            int  gmPatchId = isPerc ? p.Patch : (p.Patch + (p.Bank * 128));

                            ushort insLen = file.ReadUInt16();
                            insLen -= 2;

                            byte[] idata = new byte[24];
                            if (insLen < 24)
                            {
                                idata = file.ReadBytes(insLen);
                            }
                            else
                            {
                                idata = file.ReadBytes(24);
                                file.BaseStream.Seek(insLen - 24, System.IO.SeekOrigin.Current);
                            }

                            //var tim = Timbres[p.Patch + (isPerc ? 128 : 0)];
                            Tone tone = new Tone();
                            tone.Number = i;
                            tone.Name   = i.ToString();

                            //ins.percNoteNum = (isPerc) ? idata[0] : 0;
                            //ins.note_offset1 = (isPerc) ? 0 : idata[0];
                            //if (isPerc)
                            //{
                            //    var t = DrumTimbres[p.Patch];
                            //    t.BaseNote = (NoteNames)idata[0];
                            //    t.TimbreNumber = (ProgramAssignmentNumber)(p.Patch + 128);
                            //}

                            tone.aOp[0].AM  = (byte)((idata[1] >> 7) & 0x1);
                            tone.aOp[0].VIB = (byte)((idata[1] >> 6) & 0x1);
                            tone.aOp[0].EG  = (byte)((idata[1] >> 5) & 0x1);
                            tone.aOp[0].KSR = (byte)((idata[1] >> 4) & 0x1);
                            tone.aOp[0].ML  = (byte)((idata[1]) & 0xf);

                            tone.aOp[0].KS = (byte)((idata[2] >> 6) & 0x03);
                            tone.aOp[0].TL = (byte)((idata[2]) & 0x3f);

                            tone.aOp[0].AR = (byte)((idata[3] >> 4) & 0x0f);
                            tone.aOp[0].DR = (byte)((idata[3]) & 0x0f);

                            tone.aOp[0].SL = (byte)((idata[4] >> 4) & 0x0f);
                            tone.aOp[0].SR = -1;
                            tone.aOp[0].RR = (byte)((idata[4]) & 0x0f);

                            tone.aOp[0].WS = (byte)((idata[5]) & 0x07);

                            tone.aOp[1].AM  = (byte)((idata[7] >> 7) & 0x1);
                            tone.aOp[1].VIB = (byte)((idata[7] >> 6) & 0x1);
                            tone.aOp[1].EG  = (byte)((idata[7] >> 5) & 0x1);
                            tone.aOp[1].KSR = (byte)((idata[7] >> 4) & 0x1);
                            tone.aOp[1].ML  = (byte)((idata[7]) & 0xf);

                            tone.aOp[1].KS = (byte)((idata[8] >> 6) & 0x03);
                            tone.aOp[1].TL = (byte)((idata[8]) & 0x3f);

                            tone.aOp[1].AR = (byte)((idata[9] >> 4) & 0x0f);
                            tone.aOp[1].DR = (byte)((idata[9]) & 0x0f);

                            tone.aOp[1].SL = (byte)((idata[10] >> 4) & 0x0f);
                            tone.aOp[1].SR = -1;
                            tone.aOp[1].RR = (byte)((idata[10]) & 0x0f);

                            tone.aOp[1].WS = (byte)((idata[11]) & 0x07);

                            tone.CNT = (byte)((idata[6]) & 0x01);
                            tone.FB  = (byte)((idata[6] >> 1) & 0x07);

                            tones.Add(tone);
                        }
                    }
                }
                break;

                default:
                    return(base.ImportToneFile(fileName));
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(Exception))
                {
                    throw;
                }
                else if (ex.GetType() == typeof(SystemException))
                {
                    throw;
                }

                MessageBox.Show(Resources.FailedLoadFile + "\r\n" + ex.Message);
            }
            return(tones);
        }