Пример #1
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static int[][] GetLastOutputBuffer(InstrumentBase inst)
        {
            int[][] retbuf = new int[2][];
            int     cnt    = 0;

            try
            {
                InstrumentManager.InstExclusiveLockObject.EnterReadLock();
                cnt = instruments.Count;
            }
            finally
            {
                InstrumentManager.InstExclusiveLockObject.ExitReadLock();
            }
            uint did = inst == null ? uint.MaxValue : inst.DeviceID;
            uint un  = inst == null ? uint.MaxValue : inst.UnitNumber;

            try
            {
                Program.SoundUpdating();
                CopyData(retbuf, "lspeaker", 0, inst, cnt, did, un);
                CopyData(retbuf, "rspeaker", 1, inst, cnt, did, un);
            }
            finally
            {
                Program.SoundUpdated();
            }
            return(retbuf);
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        public YM2151GeneralContainer(InstrumentBase inst, YM2151.YM2151Timbre tim, string name) : base(tim, name)
        {
            InitializeComponent();

            this.tim = tim;

            AddControl(new RegisterValue("ALG", tim.ALG, 0, 7));
            AddControl(new RegisterValue("FB", tim.FB, 0, 7));
            AddControl(new RegisterValue("AMS", tim.AMS, 0, 3));
            AddControl(new RegisterValue("PMS", tim.PMS, 0, 7));

            AddControl(new RegisterFlag("EN", "GlobalSettings.EN", tim.GlobalSettings.EN != 0 ? true : false));
            AddControl(new RegisterValue("LFRQ", "GlobalSettings.LFRQ", tim.GlobalSettings.LFRQ == null ? -1 : tim.GlobalSettings.LFRQ.Value, 0, 255, true));
            AddControl(new RegisterValue("LFOF", "GlobalSettings.LFOF", tim.GlobalSettings.LFOF == null ? -1 : tim.GlobalSettings.LFOF.Value, 0, 1, true)).ValueChanged += LFOF_ValueChanged;
            AddControl(new RegisterValue("AMD/PMD", "GlobalSettings.LFOD", tim.GlobalSettings.LFOD == null ? -1 : tim.GlobalSettings.LFOD.Value, 0, 127, true));
            AddControl(new RegisterValue("LFOW", "GlobalSettings.LFOW", tim.GlobalSettings.LFOW == null ? -1 : tim.GlobalSettings.LFOW.Value, 0, 3, true));
            AddControl(new RegisterValue("NE", "GlobalSettings.NE", tim.GlobalSettings.NE == null ? -1 : tim.GlobalSettings.NE.Value, 0, 1, true));
            AddControl(new RegisterValue("NFRQ", "GlobalSettings.NFRQ", tim.GlobalSettings.NFRQ == null ? -1 : tim.GlobalSettings.NFRQ.Value, 0, 31, true));

            AddControl(new RegisterAlg4OpImg((RegisterValue)GetControl("ALG")));
            AddControl(new RegisterSpace("spc")
            {
                Dock = DockStyle.Right
            });
            AddControl(new RegisterOscViewer(inst));

            LFOF_ValueChanged(GetControl("GlobalSettings.LFOF"), null);
        }
Пример #3
0
        /// <summary>
        /// 更新仪器标识信息
        /// </summary>
        /// <param name="inInstrumentInfo"></param>
        /// <param name="inInstrumentObj"></param>
        private void UpdateInstrumentIdentity(InstrumentInfo inInstrumentInfo, InstrumentBase inInstrumentObj)
        {
            if (inInstrumentObj == null)
            {
                inInstrumentInfo.ModelNo      = "";
                inInstrumentInfo.Identity     = "";
                inInstrumentInfo.SN           = "";
                inInstrumentInfo.OptionList   = "";
                inInstrumentInfo.ConnectOK    = devState.error;
                inInstrumentInfo.DevInfoState = devState.error;
                inInstrumentInfo.ErrorMsgs    = "未连接";
            }
            else
            {
                inInstrumentInfo.ModelNo    = inInstrumentObj.Model;
                inInstrumentInfo.Identity   = inInstrumentObj.Identity;
                inInstrumentInfo.SN         = inInstrumentObj.SerialNumber;
                inInstrumentInfo.OptionList = inInstrumentObj.Options;

                inInstrumentInfo.Manufacter = inInstrumentObj.Manufactor;

                inInstrumentInfo.ConnectOK    = devState.connect;
                inInstrumentInfo.DevInfoState = devState.connect;
                inInstrumentInfo.ErrorMsgs    = "";
            }
        }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inst"></param>
        /// <param name="controlNo">1~8</param>
        /// <returns></returns>
        public InstancePropertyInfo[] GetPropertyInfo(InstrumentBase inst, int controlNo)
        {
            switch (controlNo)
            {
            case 1:
                return(getPropertiesInfo(inst, GeneralPurposeControl1));

            case 2:
                return(getPropertiesInfo(inst, GeneralPurposeControl2));

            case 3:
                return(getPropertiesInfo(inst, GeneralPurposeControl3));

            case 4:
                return(getPropertiesInfo(inst, GeneralPurposeControl4));

            case 5:
                return(getPropertiesInfo(inst, GeneralPurposeControl5));

            case 6:
                return(getPropertiesInfo(inst, GeneralPurposeControl6));

            case 7:
                return(getPropertiesInfo(inst, GeneralPurposeControl7));

            case 8:
                return(getPropertiesInfo(inst, GeneralPurposeControl8));
            }

            return(null);
        }
Пример #5
0
 // Use this for initialization
 void Start()
 {
     guitar   = transform.parent.gameObject.GetComponent <InstrumentBase>();
     s        = GetComponent <Slider>();
     Srect    = s.GetComponent <RectTransform>();
     Original = s.transform.localPosition;
     Resize();
 }
Пример #6
0
        /// <summary>
        ///
        /// </summary>
        public RegisterOscViewer(InstrumentBase inst) : base("OscViewer")
        {
            DoubleBuffered = true;

            InitializeComponent();
            Dock = DockStyle.Right;

            this.inst = inst;
        }
Пример #7
0
        /// <summary>
        ///
        /// </summary>
        public YM2413GeneralContainer(InstrumentBase inst, YM2413.YM2413Timbre tim, string name) : base(tim, name)
        {
            InitializeComponent();

            this.tim = tim;

            AddControl(new RegisterValue("FB", tim.FB, 0, 7));
            AddControl(new RegisterValue("SUS", tim.SUS, 0, 1));
            AddControl(new RegisterOscViewer(inst));
        }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="slot">チップ上の物理的なチャンネル(MIDI chと区別するためスロットとする)</param>
 protected SoundBase(InstrumentBase parentModule, SoundManagerBase manager, TimbreBase timbre, int baseTimbreIndex, TaggedNoteOnEvent noteOnEvent, int slot)
 {
     NoteOnEvent     = noteOnEvent;
     Slot            = slot;
     ParentModule    = parentModule;
     ParentManager   = manager;
     Timbre          = timbre;
     BaseTimbreIndex = baseTimbreIndex;
     if (ParentModule.ChannelTypes[NoteOnEvent.Channel] == ChannelType.Drum)
     {
         DrumTimbre = ParentModule.DrumTimbres[NoteOnEvent.NoteNumber];
     }
 }
 public void ShowInstrument(Type instrument)
 {
     if (!initialized)
     {
         Initialize();
     }
     foreach (var item in infoItem)
     {
         item.Value.onValueChanged.Clear();
     }
     _instrument = GameManager.Instance.GetInstrument(instrument);
     _instrument.ShowInfoPanel(infoItem);
 }
Пример #10
0
        private static void CopyData(int[][] retbuf, string name, int ch, InstrumentBase inst, int cnt, uint did, uint un)
        {
            int num = getLastOutputBufferSamples(name);

            if (num != 0)
            {
                var pbuf = getLastOutputBuffer(name, cnt, did, un);
                if (pbuf != IntPtr.Zero)
                {
                    retbuf[ch] = new int[num];
                    Marshal.Copy(pbuf, retbuf[ch], 0, num);
                }
            }
        }
Пример #11
0
        public static int FindInstrumentIndex(InstrumentBase instrument, TimbreBase timbre)
        {
            var index = -1;

            Parallel.ForEach(instrument.BaseTimbres, (tim, state, idx) =>
            {
                if (tim == timbre)
                {
                    index = (int)idx;
                    return;
                }
            });
            return(index);
        }
Пример #12
0
    void Start()
    {
        drumsIcon  = GameObject.Find("drum_buttonImage").GetComponent <Image>().sprite;
        guitarIcon = GameObject.Find("guitar_buttonImage").GetComponent <Image>().sprite;
        pianoIcon  = GameObject.Find("keyboard_buttonImage").GetComponent <Image>().sprite;

        skinInventory = GetComponent <SkinInventory>();

        instrumentBaseDrums  = GameObject.Find("Drums").GetComponent <InstrumentBase>();
        instrumentBaseGuitar = GameObject.Find("Guitar").GetComponent <InstrumentBase>();
        instrumentBasePiano  = GameObject.Find("Piano").GetComponent <InstrumentBase>();

        //FindAssets();
        NewSkin();
    }
Пример #13
0
 public void CheckActive()
 {
     inactives.Clear();
     foreach (GameObject ins in instruments)
     {
         if (ins.activeInHierarchy)
         {
             activeBase = ins.GetComponent <InstrumentBase>();
         }
         else
         {
             inactives.Add(ins);
         }
     }
 }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        /// <param name="inst"></param>
        /// <param name="target"></param>
        public static void DrawOsc(PaintEventArgs e, InstrumentBase inst, Control target, Color color)
        {
            int[][] data = InstrumentManager.GetLastOutputBuffer(inst);

            e.Graphics.Clear(target.BackColor);

            int w = target.ClientSize.Width;
            int h = target.ClientSize.Height;

            if (data != null)
            {
                using (Pen p = new Pen(color))
                {
                    int max = h * 4;
                    for (int ch = 0; ch < 2; ch++)
                    {
                        if (data[ch] != null)
                        {
                            for (int i = 0; i < data[ch].Length; i++)
                            {
                                int dt = data[ch][i];
                                max = Math.Max(Math.Abs(dt), max);
                            }
                        }
                    }
                    max += max / 10;

                    if (data[0] != null)
                    {
                        drawCore(e, p, data[0], w / 2 - 1, h / 2, 0, max);
                    }
                    if (data[1] != null)
                    {
                        drawCore(e, p, data[1], w / 2 - 1, h / 2, w / 2 + 1, max);
                    }
                }
            }
            using (Pen p = new Pen(color))
            {
                //e.Graphics.DrawLine(p, w / 2 - 1, 0, w / 2 - 1, h);
                e.Graphics.DrawLine(p, w / 2, 0, w / 2, h);
            }
        }
Пример #15
0
        public static InstrumentBase FindParentInstrument(InstrumentType instrumentType, TimbreBase timbre)
        {
            InstrumentBase inst = null;

            foreach (var i in InstrumentManager.GetInstruments((uint)instrumentType + 1))
            {
                Parallel.ForEach(i.BaseTimbres, t =>
                {
                    if (t == timbre)
                    {
                        inst = i;
                    }
                    if (inst != null)
                    {
                        return;
                    }
                });
            }
            return(inst);
        }
Пример #16
0
        /// <summary>
        ///
        /// </summary>
        public YM3812GeneralContainer(InstrumentBase inst, YM3812.YM3812Timbre tim, string name) : base(tim, name)
        {
            InitializeComponent();

            this.tim = tim;

            AddControl(new RegisterValue("ALG", tim.ALG, 0, 1));
            AddControl(new RegisterValue("FB", tim.FB, 0, 7));

            AddControl(new RegisterFlag("LFO", "GlobalSettings.EN", tim.GlobalSettings.EN != 0 ? true : false));
            AddControl(new RegisterValue("AMD", "GlobalSettings.AMD", tim.GlobalSettings.AMD == null ? -1 : tim.GlobalSettings.AMD.Value, 0, 1, true));
            AddControl(new RegisterValue("VIB", "GlobalSettings.VIB", tim.GlobalSettings.VIB == null ? -1 : tim.GlobalSettings.VIB.Value, 0, 1, true));

            AddControl(new RegisterAlg2OpImg((RegisterValue)GetControl("ALG")));
            AddControl(new RegisterSpace("spc")
            {
                Dock = DockStyle.Right
            });
            AddControl(new RegisterOscViewer(inst));
        }
Пример #17
0
        /// <summary>
        ///
        /// </summary>
        public YM2608GeneralContainer(InstrumentBase inst, YM2608.YM2608Timbre tim, string name) : base(tim, name)
        {
            InitializeComponent();

            this.tim = tim;

            AddControl(new RegisterValue("ALG", tim.ALG, 0, 7));
            AddControl(new RegisterValue("FB", tim.FB, 0, 7));
            AddControl(new RegisterValue("AMS", tim.AMS, 0, 3));
            AddControl(new RegisterValue("FMS", tim.FMS, 0, 7));

            AddControl(new RegisterFlag("LFO", "GlobalSettings.EN", tim.GlobalSettings.EN != 0 ? true : false));
            AddControl(new RegisterValue("LFOEN", "GlobalSettings.LFOEN", tim.GlobalSettings.LFOEN == null ? -1 : tim.GlobalSettings.LFOEN.Value, 0, 255, true));
            AddControl(new RegisterValue("LFRQ", "GlobalSettings.LFRQ", tim.GlobalSettings.LFRQ == null ? -1 : tim.GlobalSettings.LFRQ.Value, 0, 7, true));

            AddControl(new RegisterAlg4OpImg((RegisterValue)GetControl("ALG")));
            AddControl(new RegisterSpace("spc")
            {
                Dock = DockStyle.Right
            });
            AddControl(new RegisterOscViewer(inst));
        }
Пример #18
0
        /// <summary>
        ///
        /// </summary>
        public YMF262GeneralContainer(InstrumentBase inst, YMF262.YMF262Timbre tim, string name) : base(tim, name)
        {
            InitializeComponent();

            this.tim = tim;

            AddControl(new RegisterValue("ALG", tim.ALG, 0, 5));
            AddControl(new RegisterValue("FB", tim.FB, 0, 7));
            fb2 = new RegisterValue("FB2", tim.FB2, 0, 7);
            AddControl(fb2);

            AddControl(new RegisterFlag("LFO", "GlobalSettings.EN", tim.GlobalSettings.EN != 0 ? true : false));
            AddControl(new RegisterValue("DAM", "GlobalSettings.DAM", tim.GlobalSettings.DAM == null ? -1 : tim.GlobalSettings.DAM.Value, 0, 1, true));
            AddControl(new RegisterValue("DVB", "GlobalSettings.DVB", tim.GlobalSettings.DVB == null ? -1 : tim.GlobalSettings.DVB.Value, 0, 1, true));

            AddControl(new RegisterAlg2OpImg((RegisterValue)GetControl("ALG")));
            AddControl(new RegisterSpace("spc")
            {
                Dock = DockStyle.Right
            });
            AddControl(new RegisterOscViewer(inst));

            fb2.Enabled = (tim.ALG >= 2);
        }
Пример #19
0
        public void NoteOn(int aBank, Byte aInstrument, Byte aNote, Byte aVelocity, double aSecondLength = 0.0d)
        {
            Logger.Debug("Instrument:" + aInstrument);

            int  lBank       = aBank;
            Byte lInstrument = aInstrument;

            if (soundcluster == null)
            {
                Logger.Error("soundcluseter == null ");
            }
            else if (soundcluster.BankDictionary == null)
            {
                Logger.Error("soundcluster.BankDictionary == null ");
            }

            if (soundcluster.BankDictionary.ContainsKey(lBank) == false)
            {
                Logger.Error("Not Found Bank:" + lBank.ToString("X4"));
                lBank = 0;
            }

            if (lBank == 0x7F00)
            {
                if (lInstrument == 1)
                {
                    lInstrument = 8;
                }
                else if (lInstrument == 2)
                {
                    lInstrument = 16;
                }
                else if (lInstrument == 3)
                {
                    lInstrument = 24;
                }
                else if (lInstrument == 4)
                {
                    lInstrument = 25;
                }
                else if (lInstrument == 5)
                {
                    lInstrument = 32;
                }
                else if (lInstrument == 6)
                {
                    lInstrument = 40;
                }
                else if (lInstrument == 7)
                {
                    lInstrument = 48;
                }
            }

            if (soundcluster.BankDictionary.ContainsKey(lBank) == true)
            {
                InstrumentBase lMidiInstrument = soundcluster.BankDictionary[lBank].instrumentArray[lInstrument];

                if (lMidiInstrument == null)
                {
                    if (lBank == 0x7F00)
                    {
                        Logger.Warning("Change Instrument:" + lBank.ToString("X4") + "/" + lInstrument);
                        lInstrument = 0x0000;
                    }
                    else
                    {
                        Logger.Warning("Change Bank:" + lBank.ToString("X4") + "/" + lInstrument);

                        if (lBank != 0)
                        {
                            Logger.Error("Change Bank:" + lBank.ToString("X4") + "/" + lInstrument);
                        }

                        lBank       = 0x0000;
                        lInstrument = 0x0000;
                    }

                    lMidiInstrument = soundcluster.BankDictionary[lBank].instrumentArray[lInstrument];
                }

                if (lMidiInstrument != null)
                {
                    SoundfontBase lSoundfont = lMidiInstrument.soundfontArray[aNote];

                    if (lSoundfont != null)
                    {
                        Logger.Warning("Add");
                        noteOnList.Add(aNote);
                        oscillatorList.Add(new MidiOscillator(aNote, lInstrument, aVelocity, lSoundfont, ref midiVolume, ref midiPitch, aSecondLength));
                    }
                    else
                    {
                        Logger.Error("Not Found Note:" + lBank.ToString("X4") + "/" + lInstrument + "/" + aNote);
                    }
                }
                else
                {
                    Logger.Error("Not Found Instrument:" + lBank.ToString("X4") + "/" + lInstrument);
                }
            }
            else
            {
                Logger.Error("Not Found Bank:" + lBank.ToString("X4"));
            }
        }
Пример #20
0
        public void LoadConfig()
        {
            #region >>>>Hardware init
            try
            {
                var json_string = File.ReadAllText(File_HardwareCfg);
                HardwareCfgMgr = JsonConvert.DeserializeObject <HardwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>($"Unable to load config file { File_HardwareCfg }:{ ex.Message}", "ShowError");
            }
            InstrumentBase             inst     = null;
            HardwareCfgLevelManager1[] instCfgs = null;

            string         strClassName  = "";
            Type           t             = HardwareCfgMgr.GetType();
            PropertyInfo[] PropertyInfos = t.GetProperties();
            for (int i = 0; i < PropertyInfos.Length; i++)
            {
                if (PropertyInfos[i].Name.ToUpper().Contains("COMPORT") || PropertyInfos[i].Name.ToUpper().Contains("ETHERNET") ||
                    PropertyInfos[i].Name.ToUpper().Contains("GPIB") || PropertyInfos[i].Name.ToUpper().Contains("NIVISA") ||
                    PropertyInfos[i].Name.ToUpper().Contains("CAMERACFG"))
                {
                    continue;
                }
                PropertyInfo pi = PropertyInfos[i];
                instCfgs     = pi.GetValue(HardwareCfgMgr) as HardwareCfgLevelManager1[];
                strClassName = pi.Name.Substring(0, pi.Name.Length - 1);

                foreach (var it in instCfgs)
                {
                    if (!it.Enabled)
                    {
                        continue;
                    }
                    inst = t.Assembly.CreateInstance("RFTestAUX.Instrument." + strClassName, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as InstrumentBase;
                    if (inst != null && it.Enabled)
                    {
                        if (inst.Init())
                        {
                            InstrumentMgr.Instance.AddInstrument(it.InstrumentName, inst);
                        }
                        else
                        {
                            Messenger.Default.Send <string>($"{it.InstrumentName} init Error", "ShowError");
                        }
                    }
                }
            }
            //if (sbError.ToString().Length > 5)
            //    throw new Exception($"Instrument :{sbError.ToString()} init failed");
            #endregion

            #region >>>> Software Init
            try
            {
                var json_string = File.ReadAllText(File_ParaCfg);
                ParaMgr = JsonConvert.DeserializeObject <ParaManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>($"Unable to load config file { File_ParaCfg }:{ ex.Message}", "ShowError");
            }
            #endregion
        }
Пример #21
0
 /// <summary>
 /// 填充数据,所有属性、字段的初始化工作可以在这里完成
 /// </summary>
 public SelectInstrumentEventHandler Fill(InstrumentBase instrument)//获取当前处于活跃状态的仪器
 {
     ActiveInstrument = instrument;
     return(this);
 }
Пример #22
0
        //public static
        public void LoadConfig(out List <string> errList)
        {
            #region >>>>Hardware init
            errList = new List <string>();
            try
            {
                var json_string = File.ReadAllText(File_HardwareCfg);
                HardwareCfgMgr = JsonConvert.DeserializeObject <HardwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                errList.Add($"Unable to load config file { File_HardwareCfg}, { ex.Message}");
            }
            IMotion        motionBase     = null;
            IIO            ioBase         = null;
            InstrumentBase instrumentBase = null;
            LightBase      lightBase      = null;

            Type hardWareMgrType = HardwareCfgMgr.GetType();

            //先初始化通信端口
            foreach (var it in hardWareMgrType.GetProperties())
            {
                switch (it.Name)
                {
                case "Comports":
                    foreach (var comportCfg in HardwareCfgMgr.Comports)
                    {
                        CommunicationPortBase port = new Comport(comportCfg);
                        CommunicationMgr.Instance.AddCommunicationPort(comportCfg.PortName, port);
                    }
                    break;

                case "Ethernets":
                case "Gpibs":
                case "Visas":
                    break;

                default:
                    break;
                }
            }

            foreach (var it in hardWareMgrType.GetProperties())
            {
                switch (it.Name)
                {
                case "MotionCards":
                    var motionCfgs = it.GetValue(HardwareCfgMgr) as MotionCardCfg[];
                    if (motionCfgs == null)
                    {
                        break;
                    }
                    foreach (var motionCfg in motionCfgs)
                    {
                        if (motionCfg.Enabled)
                        {
                            motionBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.MotionCards." + motionCfg.Name.Substring(0, motionCfg.Name.IndexOf("[")), true, BindingFlags.CreateInstance, null, /*new object[] { motionCfg }*/ null, null, null) as IMotion;
                            if (motionBase != null)
                            {
                                if (motionCfg.ConnectMode.ToLower() != "none")
                                {
                                    var p        = hardWareMgrType.GetProperty($"{motionCfg.ConnectMode}s");
                                    var portCfgs = p.GetValue(HardwareCfgMgr) as ICommunicationPortCfg[];
                                    var ports    = from portCfg in portCfgs where portCfg.PortName == motionCfg.PortName select portCfg;
                                    if (ports != null && ports.Count() > 0)
                                    {
                                        if (motionBase.Init(motionCfg, ports.ElementAt(0)))
                                        {
                                            //设置单位,轴类型, 软限位等
                                            for (int i = 0; i < motionBase.MAX_AXIS - motionBase.MIN_AXIS + 1; i++)
                                            {
                                                var settings = HardwareCfgMgr.AxisSettings.Where(a => a.AxisNo == i + motionBase.MIN_AXIS);
                                                try
                                                {
                                                    motionBase.SetAxisPara(i, settings == null ? null : settings.First());
                                                }
                                                catch (Exception ex)
                                                {
                                                    errList.Add($"{ex.Message}");
                                                }
                                            }
                                            MotionMgr.Instance.AddMotionCard(motionCfg.Name, motionBase);
                                        }
                                        else
                                        {
                                            errList.Add($"{motionCfg.Name} init failed");
                                        }
                                    }
                                    else
                                    {
                                        errList.Add($"{motionCfg.Name} init failed");
                                    }
                                }
                                else      //无需选择通信端口
                                {
                                    if (motionBase.Init(motionCfg, null))
                                    {
                                        //设置单位,轴类型, 软限位等
                                        for (int i = 0; i < motionBase.MAX_AXIS - motionBase.MIN_AXIS; i++)
                                        {
                                            var settings = HardwareCfgMgr.AxisSettings.Where(a => a.AxisNo == i + motionBase.MIN_AXIS);
                                            try
                                            {
                                                motionBase.SetAxisPara(i, settings == null ? null : settings.First());
                                            }
                                            catch (Exception ex)
                                            {
                                                errList.Add($"{ex.Message}");
                                            }
                                        }
                                        MotionMgr.Instance.AddMotionCard(motionCfg.Name, motionBase);
                                    }
                                    else
                                    {
                                        errList.Add($"{motionCfg.Name} init failed");
                                    }
                                }
                            }
                            else
                            {
                                errList.Add($"{motionCfg.Name} Create instanse failed");
                            }
                        }
                    }
                    break;

                case "IOCards":
                    var ioCfgs = it.GetValue(HardwareCfgMgr) as IOCardCfg[];
                    if (ioCfgs == null)
                    {
                        break;
                    }
                    foreach (var ioCfg in ioCfgs)
                    {
                        if (ioCfg.Enabled)
                        {
                            ioBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.IOCards." + ioCfg.Name.Substring(0, ioCfg.Name.IndexOf("[")), true, BindingFlags.CreateInstance, null, null, null, null) as IIO;
                            if (ioBase != null)
                            {
                                ioBase.ioCfg = ioCfg;
                                if (ioCfg.ConnectMode.ToLower() != "none")      //没有屏蔽端口
                                {
                                    var p        = hardWareMgrType.GetProperty($"{ioCfg.ConnectMode}s");
                                    var portCfgs = p.GetValue(HardwareCfgMgr) as ICommunicationPortCfg[];
                                    var ports    = from portCfg in portCfgs where portCfg.PortName == ioCfg.PortName select portCfg;
                                    if (ports != null && ports.Count() > 0)
                                    {
                                        if (ioBase.Init(ioCfg, ports.ElementAt(0)))
                                        {
                                            IOCardMgr.Instance.AddIOCard(ioCfg.Name, ioBase);
                                        }
                                        else
                                        {
                                            errList.Add($"{ioCfg.Name} init failed");
                                        }
                                    }
                                    else
                                    {
                                        errList.Add($"{ioCfg.Name} init failed");
                                    }
                                }
                                else      //无需选择通信端口
                                {
                                    if (ioBase.Init(ioCfg, null))
                                    {
                                        IOCardMgr.Instance.AddIOCard(ioCfg.Name, ioBase);
                                    }
                                    else
                                    {
                                        errList.Add($"{ioCfg.Name} init failed");
                                    }
                                }
                            }
                            else
                            {
                                errList.Add($"{ioCfg.Name} Create instanse failed");
                            }
                        }
                    }
                    break;

                case "Instruments":
                    var instrumentCfgs = it.GetValue(HardwareCfgMgr) as InstrumentCfg[];
                    if (instrumentCfgs == null)
                    {
                        break;
                    }
                    foreach (var instrumentCfg in instrumentCfgs)
                    {
                        if (instrumentCfg.Enabled)
                        {
                            instrumentBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.Instruments." + instrumentCfg.InstrumentName.Substring(0, instrumentCfg.InstrumentName.IndexOf("[")), true, BindingFlags.CreateInstance, null, null, null, null) as InstrumentBase;
                            if (instrumentBase != null)
                            {
                                if (instrumentBase.Init())
                                {
                                }
                            }
                        }
                    }
                    break;

                case "Cameras":
                    var cameraCfgs = it.GetValue(HardwareCfgMgr) as CameraCfg[];
                    break;

                case "Lights":
                    var lightCfgs = it.GetValue(HardwareCfgMgr) as LightCfg[];
                    foreach (var lightCfg in lightCfgs)
                    {
                        if (lightCfg.Enabled)
                        {
                            lightBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.Vision.Light." + lightCfg.Name.Substring(0, lightCfg.Name.IndexOf("[")), true, BindingFlags.CreateInstance, null, null, null, null) as LightBase;
                            if (lightBase != null)
                            {
                                if (lightCfg.ConnectMode.ToLower() != "none")
                                {
                                    var p        = hardWareMgrType.GetProperty($"{lightCfg.ConnectMode}s");
                                    var portCfgs = p.GetValue(HardwareCfgMgr) as ICommunicationPortCfg[];
                                    var ports    = from portCfg in portCfgs where portCfg.PortName == lightCfg.PortName select portCfg;
                                    if (ports != null && ports.Count() > 0)
                                    {
                                        if (lightBase.Init(lightCfg, ports.ElementAt(0)))     //如果不需要初始化就直接加入字典
                                        {
                                            LigtMgr.Instance.AddLight(lightCfg.Name, lightBase);
                                        }
                                        else
                                        {
                                            errList.Add($"{lightCfg.Name} init failed");
                                        }
                                    }
                                    else
                                    {
                                        errList.Add($"{lightCfg.Name} init failed");
                                    }
                                }
                                else     //无需选择通信端口
                                {
                                    if (lightBase.Init(lightCfg, null))
                                    {
                                        LigtMgr.Instance.AddLight(lightCfg.Name, lightBase);
                                    }
                                    else
                                    {
                                        errList.Add($"{lightCfg.Name} init failed");
                                    }
                                }
                            }
                            else
                            {
                                errList.Add($"{lightCfg.Name} Create instanse failed");
                            }
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            #endregion

            #region >>>>Software init
            try
            {
                var json_string = File.ReadAllText(File_SoftwareCfg);
                SoftwareCfgMgr = JsonConvert.DeserializeObject <SoftwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                errList.Add(String.Format("Unable to load config file {0}, {1}", File_SoftwareCfg, ex.Message));
            }

            Type             tStationCfg  = SoftwareCfgMgr.GetType();
            PropertyInfo[]   pis          = tStationCfg.GetProperties();
            WorkFlowConfig[] WorkFlowCfgs = null;
            WorkFlowBase     workFlowBase = null;
            foreach (PropertyInfo pi in pis)
            {
                if (pi.Name == "WorkFlowConfigs")
                {
                    WorkFlowCfgs = pi.GetValue(SoftwareCfgMgr) as SoftwareManager.WorkFlowConfig[];
                    foreach (var it in WorkFlowCfgs)
                    {
                        if (it.Enable)
                        {
                            workFlowBase = tStationCfg.Assembly.CreateInstance("JPT_TosaTest.WorkFlow." + it.Name, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as WorkFlowBase;
                            if (workFlowBase == null)
                            {
                                errList.Add($"Station: {it.Name} Create instance failed!");
                            }
                            else
                            {
                                WorkFlowMgr.Instance.AddStation(it.Name, workFlowBase);
                            }
                        }
                    }
                }
            }
            #endregion

            #region >>>>SystemCfg
            try
            {
                var json_string = File.ReadAllText(File_SystemParaCfg);
                SystemParaCfgMgr = JsonConvert.DeserializeObject <SystemParaCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                errList.Add(String.Format("Unable to load config file {0}, {1}", File_SystemParaCfg, ex.Message));
            }
            #endregion

            #region >>>> UserCfg init
            try
            {
                var json_string = File.ReadAllText(File_UserCfg);
                UserCfgMgr = JsonConvert.DeserializeObject <UserCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                errList.Add(String.Format("Unable to load config file {0}, {1}", File_UserCfg, ex.Message));
            }
            #endregion

            #region >>>>ProcessPara
            //从文件中读取参数
            try
            {
                var json_string = File.ReadAllText(File_ProcessPara);
                ProcessDataMgr = JsonConvert.DeserializeObject <ProcessParaMgr>(json_string);
            }
            catch (Exception ex)
            {
                errList.Add(String.Format("Unable to load config file {0}, {1}", File_UserCfg, ex.Message));
            }
            #endregion
        }
Пример #23
0
        //public static
        public void LoadConfig()
        {
            #region >>>>Hardware init
            try
            {
                var json_string = File.ReadAllText(File_HardwareCfg);
                HardwareCfgMgr = JsonConvert.DeserializeObject <HardwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_HardwareCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }
            InstrumentBase             inst     = null;
            HardwareCfgLevelManager1[] instCfgs = null;
            string         strClassName         = "";
            Type           t             = HardwareCfgMgr.GetType();
            PropertyInfo[] PropertyInfos = t.GetProperties();
            for (int i = 0; i < PropertyInfos.Length; i++)
            {
                if (PropertyInfos[i].Name.ToUpper().Contains("COMPORT") || PropertyInfos[i].Name.ToUpper().Contains("ETHERNET") ||
                    PropertyInfos[i].Name.ToUpper().Contains("GPIB") || PropertyInfos[i].Name.ToUpper().Contains("NIVISA") ||
                    PropertyInfos[i].Name.ToUpper().Contains("CAMERACFG"))
                {
                    continue;
                }
                PropertyInfo pi = PropertyInfos[i];
                instCfgs     = pi.GetValue(HardwareCfgMgr) as HardwareCfgLevelManager1[];
                strClassName = pi.Name.Substring(0, pi.Name.Length - 1);
                foreach (var it in instCfgs)
                {
                    if (!it.Enabled)
                    {
                        continue;
                    }
                    inst = t.Assembly.CreateInstance("CPAS.Instrument." + strClassName, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as InstrumentBase;
                    if (inst != null && it.Enabled)
                    {
                        if (inst.Init())
                        {
                            InstrumentMgr.Instance.AddInstrument(it.InstrumentName, inst);
                        }
                        else
                        {
                            Messenger.Default.Send <string>(string.Format("Instrument :{0} init failed", it.InstrumentName), "ShowError");
                        }
                    }
                }
            }
            #endregion

            #region >>>>Software init
            try
            {
                var json_string = File.ReadAllText(File_SoftwareCfg);
                SoftwareCfgMgr = JsonConvert.DeserializeObject <SoftwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_SoftwareCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }

            Type             tStationCfg  = SoftwareCfgMgr.GetType();
            PropertyInfo[]   pis          = tStationCfg.GetProperties();
            WorkFlowConfig[] WorkFlowCfgs = null;
            WorkFlowBase     workFlowBase = null;
            foreach (PropertyInfo pi in pis)
            {
                WorkFlowCfgs = pi.GetValue(SoftwareCfgMgr) as SoftwareManager.WorkFlowConfig[];
                foreach (var it in WorkFlowCfgs)
                {
                    if (it.Enable)
                    {
                        workFlowBase = tStationCfg.Assembly.CreateInstance("CPAS.WorkFlow." + it.Name, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as WorkFlowBase;
                        WorkFlowMgr.Instance.AddStation(it.Name, workFlowBase);
                    }
                }
            }
            #endregion

            #region >>>>SystemCfg
            try
            {
                var json_string = File.ReadAllText(File_SystemParaCfg);
                SystemParaCfgMgr = JsonConvert.DeserializeObject <SystemParaCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                Messenger.Default.Send <string>(String.Format("Unable to load config file {0}, {1}", File_SystemParaCfg, ex.Message), "ShowError");
                throw new Exception(ex.Message);
            }
            #endregion
        }
Пример #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inst"></param>
        /// <param name="propertyName"></param>
        /// <returns></returns>
        private InstancePropertyInfo[] getPropertiesInfo(InstrumentBase inst, string propertyNames)
        {
            List <InstancePropertyInfo> plist = new List <InstancePropertyInfo>();
            var tt = inst.GetType();

            if (!string.IsNullOrWhiteSpace(propertyNames))
            {
                string[] propNameParts = propertyNames.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var propertyName in propNameParts)
                {
                    var fm = " " + propertyName.Trim();
                    var pn = nameRegex.Replace(removeRegex.Replace(fm, " "), "");

                    if (propertyInfoTable.ContainsKey(tt))
                    {
                        if (propertyInfoTable[tt].ContainsKey(pn))
                        {
                            var tpi = propertyInfoTable[tt][pn];
                            plist.Add(new InstancePropertyInfo(tpi.Owner, tpi.Property)
                            {
                                Formula = fm, Symbol = pn
                            });
                            continue;
                        }
                    }
                    else
                    {
                        propertyInfoTable.Add(tt, new Dictionary <string, InstancePropertyInfo>());
                    }

                    var pi = getPropertyInfo(inst, pn);
                    if (pi != null)
                    {
                        pi.Formula = fm;
                        pi.Symbol  = pn;

                        SlideParametersAttribute attribute =
                            Attribute.GetCustomAttribute(pi.Property, typeof(SlideParametersAttribute)) as SlideParametersAttribute;
                        if (attribute != null)
                        {
                            plist.Add(pi);
                            propertyInfoTable[tt][pn] = pi;
                        }
                        else
                        {
                            DoubleSlideParametersAttribute dattribute =
                                Attribute.GetCustomAttribute(pi.Property, typeof(DoubleSlideParametersAttribute)) as DoubleSlideParametersAttribute;
                            if (dattribute != null)
                            {
                                plist.Add(pi);
                                propertyInfoTable[tt][pn] = pi;
                            }
                            else
                            {
                                if (pi.Property.PropertyType == typeof(bool))
                                {
                                    plist.Add(pi);
                                    propertyInfoTable[tt][pn] = pi;
                                }
                                else if (pi.Property.PropertyType.IsEnum)
                                {
                                    plist.Add(pi);
                                    propertyInfoTable[tt][pn] = pi;
                                }
                            }
                        }
                    }
                }
            }
            return(plist.ToArray());
        }
Пример #25
0
        private InstancePropertyInfo getPropertyInfo(InstrumentBase inst, string propertyName)
        {
            object obj  = inst;
            object lobj = obj;

            // Split property name to parts (propertyName could be hierarchical, like obj.subobj.subobj.property
            string[] propertyNameParts = propertyName.Split('.');

            PropertyInfo pi = null;

            foreach (string propertyNamePart in propertyNameParts)
            {
                if (obj == null)
                {
                    return(null);
                }

                // propertyNamePart could contain reference to specific
                // element (by index) inside a collection
                if (!propertyNamePart.Contains("["))
                {
                    pi = obj.GetType().GetProperty(propertyNamePart);
                    if (pi == null)
                    {
                        return(null);
                    }
                    lobj = obj;
                    obj  = pi.GetValue(obj, null);
                }
                else
                {   // propertyNamePart is areference to specific element
                    // (by index) inside a collection
                    // like AggregatedCollection[123]
                    //   get collection name and element index
                    int    indexStart             = propertyNamePart.IndexOf("[") + 1;
                    string collectionPropertyName = propertyNamePart.Substring(0, indexStart - 1);
                    int    collectionElementIndex = Int32.Parse(propertyNamePart.Substring(indexStart, propertyNamePart.Length - indexStart - 1));
                    //   get collection object
                    pi = obj.GetType().GetProperty(collectionPropertyName);
                    if (pi == null)
                    {
                        return(null);
                    }
                    object unknownCollection = pi.GetValue(obj, null);
                    //   try to process the collection as array
                    if (unknownCollection.GetType().IsArray)
                    {
                        object[] collectionAsArray = unknownCollection as object[];
                        lobj = obj;
                        obj  = collectionAsArray[collectionElementIndex];
                    }
                    else
                    {
                        //   try to process the collection as IList
                        System.Collections.IList collectionAsList = unknownCollection as System.Collections.IList;
                        if (collectionAsList != null)
                        {
                            lobj = obj;
                            obj  = collectionAsList[collectionElementIndex];
                        }
                        else
                        {
                            // ??? Unsupported collection type
                        }
                    }
                }
            }

            return(new InstancePropertyInfo(lobj, pi));
        }
Пример #26
0
 /// <summary>
 ///
 /// </summary>
 public FormFmEditor(InstrumentBase inst, TimbreBase timbre) : this(inst, timbre, true)
 {
 }
Пример #27
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;
            VstSettings vs = (VstSettings)value;

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

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

            VstPlugin plugin = (VstPlugin)context.Instance;

            if (!openedFrame.ContainsKey(plugin))
            {
                FormVstEditorFrame dlg = new FormVstEditorFrame();
                {
                    lock (InstrumentBase.VstPluginContextLockObject)
                    {
                        var ctx = vs.VstPluginContext;
                        if (ctx != null)
                        {
                            dlg.PluginCommandStub = ctx.Context.PluginCommandStub;
                        }
                    }

                    try
                    {
                        InstrumentManager.InstExclusiveLockObject.EnterReadLock();
                        InstrumentBase targetInst = null;
                        foreach (var inst in InstrumentManager.GetAllInstruments())
                        {
                            foreach (var i in inst.VSTPlugins)
                            {
                                if (i == plugin)
                                {
                                    targetInst = inst;
                                    break;
                                }
                            }
                            if (targetInst != null)
                            {
                                break;
                            }
                        }
                        dlg.FormClosed         += Dlg_FormClosed;
                        plugin.PluginDisposing += Plugin_PluginDisposing;
                        openedFrame.Add(plugin, dlg);
                        dlg.Show(null, targetInst);
                    }
                    finally
                    {
                        InstrumentManager.InstExclusiveLockObject.ExitReadLock();
                    }
                }
            }
            else
            {
                openedFrame[plugin].BringToFront();
            }
            return(value);
        }
Пример #28
0
        //public static
        public void LoadConfig(out List <string> errList)
        {
            #region >>>>Hardware init
            errList = new List <string>();
            try
            {
                var json_string = File.ReadAllText(File_HardwareCfg);
                HardwareCfgMgr = JsonConvert.DeserializeObject <HardwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                errList.Add($"Unable to load config file { File_HardwareCfg}, { ex.Message}");
            }

            InstrumentBase instrumentBase = null;


            Type hardWareMgrType = HardwareCfgMgr.GetType();
            foreach (var it in hardWareMgrType.GetProperties())
            {
                switch (it.Name)
                {
                case "Instruments":
                    var instrumentCfgs = it.GetValue(HardwareCfgMgr) as InstrumentCfg[];
                    if (instrumentCfgs == null)
                    {
                        break;
                    }
                    foreach (var instrumentCfg in instrumentCfgs)
                    {
                        if (instrumentCfg.Enabled)
                        {
                            instrumentBase = hardWareMgrType.Assembly.CreateInstance("JPT_TosaTest.Instruments." + instrumentCfg.InstrumentName.Substring(0, instrumentCfg.InstrumentName.IndexOf("[")), true, BindingFlags.CreateInstance, null, null, null, null) as InstrumentBase;
                            if (instrumentBase != null)
                            {
                                if (instrumentBase.Init())
                                {
                                }
                            }
                        }
                    }
                    break;

                case "IOCards":
                case "MotonCards":
                case "Cameras":
                case "Lights":
                case "Comports":
                case "Ethernets":
                case "Gpibs":
                case "Visas":
                    break;

                default:
                    errList.Add("Invalid hardware type!");
                    break;
                }
            }

            #endregion

            #region >>>>Software init
            try
            {
                var json_string = File.ReadAllText(File_SoftwareCfg);
                SoftwareCfgMgr = JsonConvert.DeserializeObject <SoftwareCfgManager>(json_string);
            }
            catch (Exception ex)
            {
                errList.Add(String.Format("Unable to load config file {0}, {1}", File_SoftwareCfg, ex.Message));
            }

            Type             tStationCfg  = SoftwareCfgMgr.GetType();
            PropertyInfo[]   pis          = tStationCfg.GetProperties();
            WorkFlowConfig[] WorkFlowCfgs = null;
            WorkFlowBase     workFlowBase = null;
            foreach (PropertyInfo pi in pis)
            {
                if (pi.Name == "WorkFlowConfigs")
                {
                    WorkFlowCfgs = pi.GetValue(SoftwareCfgMgr) as WorkFlowConfig[];
                    foreach (var it in WorkFlowCfgs)
                    {
                        if (it.Enable)
                        {
                            workFlowBase = tStationCfg.Assembly.CreateInstance("GPAP.WorkFlow." + it.Name, true, BindingFlags.CreateInstance, null, new object[] { it }, null, null) as WorkFlowBase;
                            if (workFlowBase == null)
                            {
                                errList.Add($"Station: {it.Name} Create instance failed!");
                            }
                            else
                            {
                                WorkFlowMgr.Instance.AddStation(it.Name, workFlowBase);
                            }
                        }
                    }
                }
            }
            #endregion
        }
Пример #29
0
        /// <summary>
        ///
        /// </summary>
        public FormFmEditor(InstrumentBase inst, TimbreBase timbre, bool singleSelect)
        {
            InitializeComponent();

            this.singleSelect = singleSelect;

            for (int nn = 0; nn < 128; nn++)
            {
                toolStripComboBoxNote.Items.Add(MidiManager.GetNoteName((SevenBitNumber)nn) + "(" + nn + ")");
                toolStripComboBoxVelo.Items.Add(nn);
            }

            toolStripComboBoxNote.SelectedIndex = 60;
            toolStripComboBoxVelo.SelectedIndex = 127;
            toolStripComboBoxGate.SelectedIndex = 0;
            toolStripComboBoxCh.SelectedIndex   = 0;
            toolStripComboBoxCC.SelectedIndex   = 0;

            Settings.Default.SettingsLoaded    += Default_SettingsLoaded;
            toolStripButtonPlay.Checked         = Settings.Default.FmPlayOnEdit;
            toolStripButtonHook.Checked         = Settings.Default.FmHook;
            toolStripComboBoxVelo.SelectedIndex = Settings.Default.FmVelocity;
            toolStripComboBoxGate.SelectedIndex = Settings.Default.FmGateTime;
            toolStripComboBoxNote.SelectedIndex = Settings.Default.FmNote;

            if (singleSelect)
            {
                pianoControl1.TargetTimbres = new TimbreBase[] { timbre }
            }
            ;
            this.Timbre     = timbre;
            this.Instrument = inst;

            ignoreMetroComboBoxTimbres_SelectedIndexChanged = true;
            for (int i = 0; i < Instrument.BaseTimbres.Length; i++)
            {
                metroComboBoxTimbres.Items.Add(new TimbreItem(inst.BaseTimbres[i], i));
                if (inst.BaseTimbres[i] == timbre)
                {
                    TimbreNo = i;
                }
            }
            metroComboBoxTimbres.SelectedIndex = TimbreNo;
            ignoreMetroComboBoxTimbres_SelectedIndexChanged = false;

            if (singleSelect)
            {
                metroComboBoxTimbres.Enabled    = false;
                metroButtonImportAll.Enabled    = false;
                metroButtonImportAllGit.Enabled = false;
            }

            setTitle();

            InstrumentManager.InstrumentChanged += InstrumentManager_InstrumentChanged;
            InstrumentManager.InstrumentRemoved += InstrumentManager_InstrumentRemoved;

            pianoControl1.NoteOn           += PianoControl1_NoteOn;
            pianoControl1.NoteOff          += PianoControl1_NoteOff;
            pianoControl1.EntryDataChanged += PianoControl1_EntryDataChanged;

            Midi.MidiManager.MidiEventHooked += MidiManager_MidiEventHooked;
        }