-
Notifications
You must be signed in to change notification settings - Fork 4
Midi #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Midi #77
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b4f9c74
Create processing_midi crate
catilac 99e6f5d
switch to forked version of bevy_midi for bevy dev branch support
catilac 87caa62
switch to primary repo for bevy_midi
catilac 5c88e04
stub midi example code
catilac c99ef4f
Generic CommandBuffer<T>, and processing_utils crate
catilac a9701de
Fixing code broken by new bevy version
catilac 944bc33
PR feedback
catilac 51726f8
Revert CommandBuffer<T> abstraction
catilac File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [package] | ||
| name = "processing_midi" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
|
|
||
| [dependencies] | ||
| bevy = { workspace = true } | ||
| bevy_midi = { git = "https://github.com/BlackPhlox/bevy_midi", branch = "latest" } | ||
|
|
||
|
|
||
| [lints] | ||
| workspace = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| use bevy::prelude::*; | ||
| use bevy_midi::prelude::*; | ||
|
|
||
| pub struct MidiPlugin; | ||
|
|
||
| impl Plugin for MidiPlugin { | ||
| fn build(&self, app: &mut App) { | ||
| app.insert_resource(MidiOutputSettings { | ||
| port_name: "output", | ||
| }) | ||
| .add_plugins(MidiOutputPlugin); | ||
| } | ||
| } | ||
|
|
||
| enum MidiCommand {} | ||
|
|
||
| pub fn connect(port: usize) { | ||
| // we need to work with the ECS | ||
| // do we pass a MidiCommand to Bevy? | ||
| } | ||
|
|
||
| pub fn disconnect() {} | ||
| pub fn refresh_ports() {} | ||
|
|
||
| pub fn play_notes() {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| //! configured to render to a specific surface (either a window or an offscreen image). | ||
| use bevy::{ | ||
| camera::{ | ||
| CameraMainTextureUsages, CameraOutputMode, CameraProjection, ClearColorConfig, | ||
| CameraMainTextureUsages, CameraOutputMode, CameraProjection, ClearColorConfig, Hdr, | ||
| ImageRenderTarget, MsaaWriteback, Projection, RenderTarget, visibility::RenderLayers, | ||
| }, | ||
| core_pipeline::tonemapping::Tonemapping, | ||
|
|
@@ -20,7 +20,7 @@ use bevy::{ | |
| }, | ||
| renderer::{RenderDevice, RenderQueue}, | ||
| sync_world::MainEntity, | ||
| view::{Hdr, ViewTarget, prepare_view_targets}, | ||
| view::{ViewTarget, prepare_view_targets}, | ||
| }, | ||
| window::WindowRef, | ||
| }; | ||
|
|
@@ -52,7 +52,7 @@ impl Plugin for GraphicsPlugin { | |
| .add_systems( | ||
| Render, | ||
| send_view_targets | ||
| .in_set(RenderSystems::ManageViews) | ||
| .in_set(RenderSystems::PrepareViews) | ||
| .after(prepare_view_targets), | ||
| ) | ||
| .insert_resource(GraphicsTargetSender(tx)); | ||
|
|
@@ -220,14 +220,14 @@ pub fn create( | |
| .spawn(( | ||
| Camera3d::default(), | ||
| Camera { | ||
| target, | ||
| // always load the previous frame (provides sketch like behavior) | ||
| clear_color: ClearColorConfig::None, | ||
| // TODO: toggle this conditionally based on whether we need to write back MSAA | ||
| // when doing manual pixel udpates | ||
| msaa_writeback: MsaaWriteback::Always, | ||
| ..default() | ||
| }, | ||
| target, | ||
catilac marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // default to floating point texture format | ||
| Hdr, | ||
| // tonemapping prevents color accurate readback, so we disable it | ||
|
|
@@ -243,7 +243,7 @@ pub fn create( | |
| Transform::from_xyz(0.0, 0.0, 999.9), | ||
| render_layer, | ||
| CommandBuffer::new(), | ||
| RenderState::new(), | ||
| RenderState::default(), | ||
| SurfaceSize(width, height), | ||
| Graphics { | ||
| readback_buffer, | ||
|
|
@@ -294,6 +294,10 @@ pub fn mode_3d( | |
| let near = camera_z / 10.0; | ||
| let far = camera_z * 10.0; | ||
|
|
||
| // TODO: Setting this as a default, but we need to think about API around | ||
| // a user defined value | ||
| let near_clip_plane = vec4(0.0, 0.0, -1.0, -near); | ||
|
Comment on lines
+297
to
+299
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm putting value here for now. But after this gets merged, we'll need an issue to create intentional API around near_clip_plane. We want to support portals :P |
||
|
|
||
| let mut projection = projections | ||
| .get_mut(entity) | ||
| .map_err(|_| ProcessingError::GraphicsNotFound)?; | ||
|
|
@@ -303,6 +307,7 @@ pub fn mode_3d( | |
| aspect_ratio: aspect, | ||
| near, | ||
| far, | ||
| near_clip_plane, | ||
| }); | ||
|
|
||
| let mut transform = transforms | ||
|
|
@@ -352,6 +357,7 @@ pub fn perspective( | |
| aspect_ratio, | ||
| near, | ||
| far, | ||
| near_clip_plane, | ||
| }, | ||
| )): In<(Entity, PerspectiveProjection)>, | ||
| mut projections: Query<&mut Projection>, | ||
|
|
@@ -365,6 +371,7 @@ pub fn perspective( | |
| aspect_ratio, | ||
| near, | ||
| far, | ||
| near_clip_plane, | ||
| }); | ||
|
|
||
| Ok(()) | ||
|
|
@@ -527,7 +534,7 @@ pub fn readback( | |
| }); | ||
|
|
||
| render_device | ||
| .poll(PollType::Wait) | ||
| .poll(PollType::wait_indefinitely()) | ||
| .expect("Failed to poll device for map async"); | ||
|
|
||
| r.recv().expect("Failed to receive the map_async message"); | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| mod glfw; | ||
|
|
||
| use glfw::GlfwContext; | ||
| use processing::prelude::*; | ||
| use processing_render::render::command::DrawCommand; | ||
|
|
||
| fn main() { | ||
| match sketch() { | ||
| Ok(_) => { | ||
| eprintln!("Sketch completed successfully"); | ||
| exit(0).unwrap(); | ||
| } | ||
| Err(e) => { | ||
| eprintln!("Sketch error: {:?}", e); | ||
| exit(1).unwrap(); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| fn sketch() -> error::Result<()> { | ||
| let mut glfw_ctx = GlfwContext::new(400, 400)?; | ||
| init(Config::default())?; | ||
|
|
||
| let width = 400; | ||
| let height = 400; | ||
| let scale_factor = 1.0; | ||
|
|
||
| let surface = glfw_ctx.create_surface(width, height, scale_factor)?; | ||
| let graphics = graphics_create(surface, width, height)?; | ||
|
|
||
| processing_midi::connect(0); | ||
|
|
||
| while glfw_ctx.poll_events() { | ||
| graphics_begin_draw(graphics)?; | ||
|
|
||
| graphics_record_command( | ||
| graphics, | ||
| DrawCommand::Rect { | ||
| x: 10.0, | ||
| y: 10.0, | ||
| w: 100.0, | ||
| h: 100.0, | ||
| radii: [0.0, 0.0, 0.0, 0.0], | ||
| }, | ||
| )?; | ||
|
|
||
| graphics_end_draw(graphics)?; | ||
| } | ||
| Ok(()) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to make a few changes to
bevy_midito support things like hot-plugging. Right now it assumes that devices are available on startup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh okay good to know! in this PR the midi stuff is so early because of the bevy updates. i was going to keep working on this, but i'm wondering if we could land the bevy changes just so main has them