-
Notifications
You must be signed in to change notification settings - Fork 419
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
Implement MIDI input support #2804
Merged
Merged
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
748dd68
Implement MIDI input
holly-hacker 8f4ff56
Don't throw if MIDI input cannot be initialized (eg. missing asound)
holly-hacker d1d88ff
Enable MidiInputHandler for Android and iOS
holly-hacker b67a97b
Handle Running Status messages
holly-hacker 5e7cab0
Handle midi event edge cases
holly-hacker 0c43156
Include velocity in Midi events
holly-hacker 14d2d11
Move MidiInputHandler to correct namespace
holly-hacker 0a16a99
Manually (and properly) parse MIDI messages
holly-hacker 068b07f
Fix code style issues
holly-hacker a22e62e
Remove remaining TODO comment
holly-hacker 21d6ada
Fix missing imports in Android and iOS projects
holly-hacker c11b145
Add Midi keys to InputKey
holly-hacker 78b1c63
Remove accidental using statement
holly-hacker c669b13
Track Midi events in FrameStatistics
holly-hacker 6f588aa
Update managed-midi to 1.9.6
holly-hacker 0a408fd
Merge remote-tracking branch 'origin/master' into midi-input
smoogipoo feeda0a
Update managed-midi
smoogipoo dd1ad39
Merge branch 'master' into midi-input
smoogipoo 3c154a8
Remove unnecessary clone
smoogipoo c633835
Update managed-midi
holly-hacker fc54002
Fix return parameter of OnMidiUp, add doc comments
holly-hacker aac4366
Use ButtonEventManager instead of manually calling handleMidiKey*
holly-hacker cc44d6c
Improve error handling in case of invalid MIDI messages
holly-hacker 6769cd1
Fix up debug logging
holly-hacker b7fcba7
Merge branch 'master' into midi-input
smoogipoo 89ad557
Make velocities public
smoogipoo 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
This file contains 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 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,104 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Shapes; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Input; | ||
using osu.Framework.Input.Events; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Framework.Tests.Visual.Input | ||
{ | ||
public class TestSceneMidi : FrameworkTestScene | ||
{ | ||
public TestSceneMidi() | ||
{ | ||
var keyFlow = new FillFlowContainer | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
AutoSizeAxes = Axes.Y, | ||
}; | ||
|
||
for (MidiKey k = MidiKey.A0; k < MidiKey.C8; k++) | ||
keyFlow.Add(new MidiKeyHandler(k)); | ||
|
||
Child = keyFlow; | ||
} | ||
|
||
protected override bool OnMidiDown(MidiDownEvent e) | ||
{ | ||
Console.WriteLine(e); | ||
return base.OnMidiDown(e); | ||
} | ||
|
||
protected override bool OnMidiUp(MidiUpEvent e) | ||
{ | ||
Console.WriteLine(e); | ||
return base.OnMidiUp(e); | ||
} | ||
|
||
protected override bool Handle(UIEvent e) | ||
{ | ||
if (!(e is MouseEvent)) | ||
Console.WriteLine("Event: " + e); | ||
return base.Handle(e); | ||
} | ||
|
||
private class MidiKeyHandler : CompositeDrawable | ||
{ | ||
private readonly Drawable background; | ||
|
||
public override bool HandleNonPositionalInput => true; | ||
|
||
private readonly MidiKey key; | ||
|
||
public MidiKeyHandler(MidiKey key) | ||
{ | ||
this.key = key; | ||
|
||
Size = new Vector2(50); | ||
|
||
InternalChildren = new[] | ||
{ | ||
background = new Container | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Colour = Color4.DarkGreen, | ||
Alpha = 0, | ||
Child = new Box { RelativeSizeAxes = Axes.Both } | ||
}, | ||
new SpriteText | ||
{ | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Text = key.ToString().Replace("Sharp", "#") | ||
} | ||
}; | ||
} | ||
|
||
protected override bool OnMidiDown(MidiDownEvent e) | ||
{ | ||
if (e.Key != key) | ||
return base.OnMidiDown(e); | ||
|
||
const float base_opacity = 0.25f; // to make a velocity of 1 not completely invisible | ||
|
||
background.FadeTo(base_opacity + e.Velocity / 128f * (1 - base_opacity), 100, Easing.OutQuint); | ||
return true; | ||
} | ||
|
||
protected override bool OnMidiUp(MidiUpEvent e) | ||
{ | ||
if (e.Key != key) | ||
return base.OnMidiUp(e); | ||
|
||
background.FadeOut(100); | ||
return true; | ||
} | ||
} | ||
} | ||
} |
This file contains 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 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
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.
Should return
void
(andfalse
inTriggerEvent()
).