private void DisableKDMAPI_Click(object sender, RoutedEventArgs e) { if (OmniMIDIDisabled) { disableKDMAPI.Content = Resources["disableKDMAPI"]; OmniMIDIDisabled = false; settings.playbackEnabled = true; try { Console.WriteLine("Loading KDMAPI..."); KDMAPI.InitializeKDMAPIStream(); Console.WriteLine("Loaded!"); } catch { } } else { disableKDMAPI.Content = Resources["enableKDMAPI"]; OmniMIDIDisabled = true; settings.playbackEnabled = false; try { Console.WriteLine("Unloading KDMAPI"); KDMAPI.TerminateKDMAPIStream(); } catch { } } }
public static void Main() { new MainWindow().ShowDialog(); return; MidiLoader loader = new MidiLoader("F:/Music/Black MIDIs/Evans LOLEX MODE II 4.0.mid"); KDMAPI.InitializeKDMAPIStream(); Console.WriteLine("Playing..."); Timer timer = new Timer(); for (uint i = 0; i < loader.File.MIDINoteEvents.Length; i++) { StartThread(loader.File.MIDINoteEvents[i], timer); } timer.Start(); Thread.Sleep(-1); KDMAPI.TerminateKDMAPIStream(); }
public MainWindow() { InitializeComponent(); SourceInitialized += (s, e) => { IntPtr handle = (new WindowInteropHelper(this)).Handle; HwndSource.FromHwnd(handle).AddHook(new HwndSourceHook(WindowProc)); }; tempoMultSlider.nudToSlider = v => Math.Log(v, 2); tempoMultSlider.sliderToNud = v => Math.Pow(2, v); dynamic sett = JsonConvert.DeserializeObject(File.ReadAllText("settings.json")); if (sett.defaultBackground != "") { try { bgImagePath.Text = sett.defaultBackground; settings.BGImage = new Bitmap(bgImagePath.Text); } catch { settings.BGImage = null; if (bgImagePath.Text != "") { MessageBox.Show("Couldn't load default background image"); } } } if ((bool)sett.ignoreKDMAPI) { foundOmniMIDI = false; } defaultPlugin = (string)sett.defaultPlugin; JArray size = sett.settingsWindowSize; Width = (double)size[0]; Height = (double)size[1]; Task omnimidiLoader = null; if (foundOmniMIDI) { omnimidiLoader = Task.Run(() => { try { KDMAPI.InitializeKDMAPIStream(); Console.WriteLine("Loaded KDMAPI!"); } catch { Console.WriteLine("Failed to load KDMAPI, disabling"); foundOmniMIDI = false; } }); } if (!foundOmniMIDI) { disableKDMAPI.IsEnabled = false; } settings = new RenderSettings(); settings.PauseToggled += ToggledPause; InitialiseSettingsValues(); creditText.Text = "Video was rendered with Zenith\nhttps://arduano.github.io/Zenith-MIDI/start"; var languagePacks = Directory.GetDirectories("Languages"); foreach (var language in languagePacks) { var resources = Directory.GetFiles(language).Where((l) => l.EndsWith(".xaml")).ToList(); if (resources.Count == 0) { continue; } Dictionary <string, ResourceDictionary> fullDict = new Dictionary <string, ResourceDictionary>(); foreach (var r in resources) { ResourceDictionary file = new ResourceDictionary(); file.Source = new Uri(Path.GetFullPath(r), UriKind.RelativeOrAbsolute); var name = Path.GetFileNameWithoutExtension(r); fullDict.Add(name, file); } if (!fullDict.ContainsKey("window")) { continue; } if (fullDict["window"].Contains("LanguageName") && fullDict["window"]["LanguageName"].GetType() == typeof(string)) { Languages.Add(fullDict); } } Languages.Sort(new Comparison <Dictionary <string, ResourceDictionary> >((d1, d2) => { if ((string)d1["window"]["LanguageName"] == "English") { return(-1); } if ((string)d2["window"]["LanguageName"] == "English") { return(1); } else { return(0); } })); foreach (var lang in Languages) { var item = new ComboBoxItem() { Content = lang["window"]["LanguageName"] }; languageSelect.Items.Add(item); } languageSelect.SelectedIndex = 0; if (omnimidiLoader != null) { omnimidiLoader.GetAwaiter().GetResult(); } }