public void Init() { #region init_gfx Form = new RenderForm("Kazedan"); var factory = new FactoryD2D(); SizeF dpi = factory.DesktopDpi; var swapChainDesc = new SwapChainDescription() { BufferCount = 2, Usage = Usage.RenderTargetOutput, OutputHandle = Form.Handle, IsWindowed = true, ModeDescription = new ModeDescription((int)(GFXResources.Bounds.Width * (dpi.Width / 96f)), (int)(GFXResources.Bounds.Height * (dpi.Height / 96f)), new Rational(60, 1), Format.R8G8B8A8_UNorm), SampleDescription = new SampleDescription(1, 0), Flags = SwapChainFlags.AllowModeSwitch, SwapEffect = SwapEffect.Discard, }; Device device; SwapChain swapChain; Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, swapChainDesc, out device, out swapChain); Surface backBuffer = Surface.FromSwapChain(swapChain, 0); renderTarget = RenderTarget.FromDXGI(factory, backBuffer, new RenderTargetProperties() { HorizontalDpi = dpi.Width, VerticalDpi = dpi.Height, MinimumFeatureLevel = SlimDX.Direct2D.FeatureLevel.Default, PixelFormat = new PixelFormat(Format.R8G8B8A8_UNorm, AlphaMode.Ignore), Type = RenderTargetType.Default, Usage = RenderTargetUsage.None }); factory.Dispose(); // Freaking antialiasing lagging up my programs renderTarget.AntialiasMode = AntialiasMode.Aliased; renderTarget.TextAntialiasMode = TextAntialiasMode.Grayscale; using (var DXGIFactory = swapChain.GetParent <FactoryDXGI>()) DXGIFactory.SetWindowAssociation(Form.Handle, WindowAssociationFlags.IgnoreAltEnter); Form.ClientSize = GFXResources.Bounds; Form.AutoSizeMode = AutoSizeMode.GrowAndShrink; Form.Icon = Properties.Resources.KazedanIcon; #endregion GFXResources.Init(renderTarget); Form.KeyDown += (o, e) => { Keys key = e.KeyCode; switch (key) { case Keys.F11: swapChain.IsFullScreen = !swapChain.IsFullScreen; break; case Keys.F: Sequencer.NoteManager.UserEnabledFancy = !Sequencer.NoteManager.UserEnabledFancy; Sequencer.NoteManager.RenderFancy = Sequencer.NoteManager.UserEnabledFancy; break; case Keys.Up: Sequencer.Delay += 100; Sequencer.Reset(); break; case Keys.Down: if (Sequencer.Delay >= 100) { Sequencer.Delay -= 100; Sequencer.Reset(); } break; case Keys.Left: if (GFXResources.NoteOffset > 0) { GFXResources.NoteOffset--; } break; case Keys.Right: if (GFXResources.NoteOffset < 128 - GFXResources.NoteCount) { GFXResources.NoteOffset++; } break; case Keys.D: Sequencer.ShowDebug = !Sequencer.ShowDebug; break; case Keys.Space: if (Sequencer.Stopped) { Sequencer.Start(); } else { Sequencer.Stop(); } break; } }; // Start loading thread Thread loadThread = new Thread(Load); loadThread.Start(); // Show controller window Thread controlThread = new Thread(() => { loadThread.Join(); Application.EnableVisualStyles(); ControlForm = new KZControl(Sequencer); Application.Run(ControlForm); }); controlThread.SetApartmentState(ApartmentState.STA); controlThread.Start(); // Make sure the control form closes when the main form does Form.Disposed += (o, e) => { ControlForm?.BeginInvoke((MethodInvoker) delegate { ControlForm.Close(); }); }; MessagePump.Run(Form, () => { // Do sequencer tick if (!Sequencer.Stopped) { Sequencer.UpdateNotePositions(); Sequencer.UpdateRenderer(); } Paint(renderTarget); // Calculate profiling information long tick = Environment.TickCount; if (tick - LastSample >= SampleRate) { Elapsed = tick - LastTick; LastSample = tick; } LastTick = tick; swapChain.Present(1, PresentFlags.None); }); renderTarget.Dispose(); swapChain.Dispose(); device.Dispose(); Sequencer.Dispose(); }
private void btnLoad_Click(object sender, EventArgs e) { Sequencer.Stop(); Sequencer.Reset(); Sequencer.Load(Path); }