/// <summary> /// /// </summary> static InstrumentManager() { var funcPtr = MameIF.GetProcAddress("getLastOutputBuffer"); if (funcPtr != IntPtr.Zero) { getLastOutputBuffer = Marshal.GetDelegateForFunctionPointer <delegate_getLastOutputBuffer>(funcPtr); } funcPtr = MameIF.GetProcAddress("getLastOutputBufferSamples"); if (funcPtr != IntPtr.Zero) { getLastOutputBufferSamples = Marshal.GetDelegateForFunctionPointer <delegate_getLastOutputBufferSamples>(funcPtr); } Midi.MidiManager.MidiEventReceivedA += MidiManager_MidiEventReceivedA; Midi.MidiManager.MidiEventReceivedB += MidiManager_MidiEventReceivedB; for (int i = 0; i < Enum.GetNames(typeof(InstrumentType)).Length; i++) { instruments.Add(new List <InstrumentBase>()); } NrpnLsb = new byte[2, 16]; NrpnMsb = new byte[2, 16]; RpnLsb = new byte[2, 16]; RpnMsb = new byte[2, 16]; DataLsb = new byte[2, 16]; DataMsb = new byte[2, 16]; sysExData.Add(new List <byte>()); sysExData.Add(new List <byte>()); Program.ShuttingDown += Program_ShuttingDown; }
/// <summary> /// /// </summary> static Beep() { IntPtr funcPtr = MameIF.GetProcAddress("beep_set_clock"); if (funcPtr != IntPtr.Zero) { Beep_set_clock = (delegate_beep_set_clock)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_beep_set_clock)); } }
/// <summary> /// /// </summary> static uPD1771C() { IntPtr funcPtr = MameIF.GetProcAddress("uPD1771_write"); if (funcPtr != IntPtr.Zero) { uPD1771_write = (delegate_uPD1771_write)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_uPD1771_write)); } }
/// <summary> /// /// </summary> static SP0256() { IntPtr funcPtr = MameIF.GetProcAddress("sp0256_ald_w"); if (funcPtr != IntPtr.Zero) { sp0256_ald_w = (delegate_sp0256_ald_w)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sp0256_ald_w)); } funcPtr = MameIF.GetProcAddress("sp0256_sby_r"); if (funcPtr != IntPtr.Zero) { sp0256_sby_r = (delegate_sp0256_sby_r)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sp0256_sby_r)); } funcPtr = MameIF.GetProcAddress("sp0256_lrq_r"); if (funcPtr != IntPtr.Zero) { sp0256_lrq_r = (delegate_sp0256_lrq_r)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sp0256_lrq_r)); } funcPtr = MameIF.GetProcAddress("sp0256_set_clock"); if (funcPtr != IntPtr.Zero) { sp0256_set_clock = (delegate_sp0256_set_clock)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sp0256_set_clock)); } AllophoneDictionary = new Dictionary <string, byte>(); for (byte i = 0; i < AllophoneTable.Length; i++) { AllophoneDictionary.Add(AllophoneTable[i], i); } PhoneDictionary = new Dictionary <string, string>(); for (int i = 0; i < CmuTable.Length / 2; i++) { PhoneDictionary.Add(CmuTable[i * 2], CmuTable[i * 2 + 1]); } CmuDictionary = new Dictionary <string, string[]>(); using (StringReader sr = new StringReader(Resources.cmudict_0_7b)) { string line; string[] split1 = new string[] { " " }; while ((line = sr.ReadLine()) != null) { if (line.StartsWith(";")) { continue; } string[] word = line.Split(split1, StringSplitOptions.RemoveEmptyEntries); if (word.Length == 2) { CmuDictionary.Add(word[0], convertAllophones(word[1].Split(' '))); } } } CmuDictionary.Add("MAmidiMEmo", new string[] { "MM", "AR", "MM", "IY", "DH1", "IY", "MM", "EH", "MM", "OR" }); CmuDictionary.Add("Chiptune", new string[] { "CH", "IH", "PP", "CH", "UW1", "NG" }); }
/// <summary> /// /// </summary> static SN76496() { IntPtr funcPtr = MameIF.GetProcAddress("sn76496_write"); if (funcPtr != IntPtr.Zero) { Sn76496_write = (delegate_sn76496_write)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sn76496_write)); } }
/// <summary> /// /// </summary> static TMS5220() { IntPtr funcPtr = MameIF.GetProcAddress("tms5220_data_w"); if (funcPtr != IntPtr.Zero) { Tms5220_data_w = (delegate_tms5220_data_w)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_tms5220_data_w)); } funcPtr = MameIF.GetProcAddress("tms5220_status_r"); if (funcPtr != IntPtr.Zero) { Tms5220_status_r = (delegate_tms5220_status_r)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_tms5220_status_r)); } }
/// <summary> /// /// </summary> static NAMCO_CUS30() { IntPtr funcPtr = MameIF.GetProcAddress("namco_cus30_w"); if (funcPtr != IntPtr.Zero) { namco_cus30_w = (delegate_namco_cus30_w)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_namco_cus30_w)); } funcPtr = MameIF.GetProcAddress("namco_cus30_r"); if (funcPtr != IntPtr.Zero) { namco_cus30_r = (delegate_namco_cus30_r)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_namco_cus30_r)); } }
/// <summary> /// /// </summary> static CM32P() { IntPtr funcPtr = MameIF.GetProcAddress("cm32p_play_msg"); if (funcPtr != IntPtr.Zero) { CM32P_play_msg = (delegate_CM32P_play_msg)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_play_msg)); } funcPtr = MameIF.GetProcAddress("cm32p_play_sysex"); if (funcPtr != IntPtr.Zero) { CM32P_play_sysex = (delegate_CM32P_play_sysex)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_play_sysex)); } funcPtr = MameIF.GetProcAddress("cm32p_load_sf"); if (funcPtr != IntPtr.Zero) { CM32P_load_sf = (delegate_CM32P_load_sf)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_load_sf)); } funcPtr = MameIF.GetProcAddress("cm32p_add_sf"); if (funcPtr != IntPtr.Zero) { CM32P_add_sf = (delegate_CM32P_add_sf)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_add_sf)); } funcPtr = MameIF.GetProcAddress("cm32p_set_tone"); if (funcPtr != IntPtr.Zero) { CM32P_set_tone = (delegate_CM32P_set_tone)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_set_tone)); } funcPtr = MameIF.GetProcAddress("cm32p_initialize_memory"); if (funcPtr != IntPtr.Zero) { CM32P_initlaize_memory = (delegate_CM32P_initlaize_memory)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_initlaize_memory)); } funcPtr = MameIF.GetProcAddress("cm32p_set_card"); if (funcPtr != IntPtr.Zero) { CM32P_set_card = (delegate_CM32P_set_card)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_set_card)); } funcPtr = MameIF.GetProcAddress("cm32p_get_chanAssign"); if (funcPtr != IntPtr.Zero) { CM32P_get_chanAssign = (delegate_CM32P_get_chanAssign)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_get_chanAssign)); } funcPtr = MameIF.GetProcAddress("cm32p_set_chanAssign"); if (funcPtr != IntPtr.Zero) { CM32P_set_chanAssign = (delegate_CM32P_set_chanAssign)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_CM32P_set_chanAssign)); } }
/// <summary> /// /// </summary> static C140() { IntPtr funcPtr = MameIF.GetProcAddress("c140_w"); if (funcPtr != IntPtr.Zero) { c140_w = (delegate_c140_w)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_c140_w)); } funcPtr = MameIF.GetProcAddress("c140_set_callback"); if (funcPtr != IntPtr.Zero) { set_callback = (delegate_set_callback)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_set_callback)); } }
/// <summary> /// /// </summary> static MT32() { IntPtr funcPtr = MameIF.GetProcAddress("mt32_play_msg"); if (funcPtr != IntPtr.Zero) { mt32_play_msg = (delegate_mt32_play_msg)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_mt32_play_msg)); } funcPtr = MameIF.GetProcAddress("mt32_play_sysex"); if (funcPtr != IntPtr.Zero) { mt32_play_sysex = (delegate_mt32_play_sysex)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_mt32_play_sysex)); } channelEventParameters = typeof(ChannelEvent).GetField("_parameters", BindingFlags.NonPublic | BindingFlags.Instance); }
/// <summary> /// /// </summary> static GB_APU() { IntPtr funcPtr = MameIF.GetProcAddress("gb_apu_write"); if (funcPtr != IntPtr.Zero) { GbApu_write = (delegate_gb_apu_write)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_gb_apu_write)); } funcPtr = MameIF.GetProcAddress("gb_apu_read"); if (funcPtr != IntPtr.Zero) { GbApu_read = (delegate_gb_apu_read)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_gb_apu_read)); } funcPtr = MameIF.GetProcAddress("gb_apu_wave_write"); if (funcPtr != IntPtr.Zero) { GbApu_wave_write = (delegate_gb_apu_wave_write)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_gb_apu_wave_write)); } }
/// <summary> /// /// </summary> static SAM() { IntPtr funcPtr = MameIF.GetProcAddress("sam_start_raw"); if (funcPtr != IntPtr.Zero) { sam_start_raw = (delegate_sam_start_raw)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sam_start_raw)); } funcPtr = MameIF.GetProcAddress("sam_stop"); if (funcPtr != IntPtr.Zero) { sam_stop = (delegate_sam_stop)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sam_stop)); } funcPtr = MameIF.GetProcAddress("sam_set_frequency"); if (funcPtr != IntPtr.Zero) { sam_set_frequency = (delegate_sam_set_frequency)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sam_set_frequency)); } funcPtr = MameIF.GetProcAddress("sam_set_volume"); if (funcPtr != IntPtr.Zero) { sam_set_volume = (delegate_sam_set_volume)Marshal.GetDelegateForFunctionPointer(funcPtr, typeof(delegate_sam_set_volume)); } }
/// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> /// <param name="parentModule">親モジュール</param> public static void Main(IntPtr parentModule) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; System.Resources.ResourceManager rm = new System.Resources.ResourceManager("System", typeof(UriFormat).Assembly); string dummy = rm.GetString("Arg_EmptyOrNullString"); ThreadPool.SetMaxThreads(250, 1000); MameIF.Initialize(parentModule); var threadStart = new ManualResetEvent(false); mainThread = new Thread(new ThreadStart(() => { threadStart.Set(); Settings.Default.Reload(); if (string.IsNullOrWhiteSpace(Settings.Default.OutputDir)) { Settings.Default.OutputDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); } f_CurrentSamplingRate = 48000; int.TryParse(Settings.Default.SampleRate, out f_CurrentSamplingRate); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); using (var fs = new FormSplash()) { fs.Show(); if (!IsVSTiMode()) { while (fs.Opacity != 1) { fs.Opacity += 0.1; Thread.Sleep(50); fs.Refresh(); } } else { formSplash = fs; fs.Opacity += 1; fs.Refresh(); } try { var fm = new FormMain(); fm.Shown += (_, __) => { if (!IsVSTiMode()) { fm.BeginInvoke(new MethodInvoker(() => { fs.Close(); })); } if (!string.IsNullOrEmpty(Settings.Default.EnvironmentSettings)) { try { var dso = StringCompressionUtility.Decompress(Settings.Default.EnvironmentSettings); InstrumentManager.ClearAllInstruments(); var settings = JsonConvert.DeserializeObject <EnvironmentSettings>(dso, JsonAutoSettings); InstrumentManager.RestoreSettings(settings); } catch (Exception ex) { if (ex.GetType() == typeof(Exception)) { throw; } else if (ex.GetType() == typeof(SystemException)) { throw; } MessageBox.Show(ex.ToString()); } } }; Application.Run(fm); var so = JsonConvert.SerializeObject(SaveEnvironmentSettings(), Formatting.Indented, JsonAutoSettings); Settings.Default.EnvironmentSettings = StringCompressionUtility.Compress(so); Settings.Default.Save(); } catch (Exception ex) { if (ex.GetType() == typeof(Exception)) { throw; } else if (ex.GetType() == typeof(SystemException)) { throw; } MessageBox.Show(ex.ToString()); } ShuttingDown?.Invoke(typeof(Program), EventArgs.Empty); } })) { Priority = ThreadPriority.BelowNormal }; mainThread.SetApartmentState(ApartmentState.STA); mainThread.Start(); threadStart.WaitOne(); }