Comments (18)
Hi,
Thanks for your question! At now it's not possible, but I'll add corresponding event to the Playback
class as soon as possible.
from drywetmidi.
@ianespana , I've added EventPlayed
event (09b7c45) to Playback
class so you can react on every played event even without OutputDevice
set. You can build the library from sources (develop branch) to try the new feature right now.
from drywetmidi.
Perfect! I'll try it out and let you know if I find any issues. Thanks a lot!
from drywetmidi.
Sounds good :) Waiting for your response.
from drywetmidi.
So, it works. But now I'm facing two new issues.
The first one is that I'm just stupid and was trying to reopen the same device again... Nevermind!
The second thing I'd like to as is if it's possible to get the MIDI's tick so I can implement a scroll bar to my program which moves forward as the song progresses
from drywetmidi.
You can take current time in MIDI ticks via GetCurrentTime<MidiTimeSpan>()
method of the Playback
class.
from drywetmidi.
I think I expressed wrong. I want an even to trigger on every tick of the MIDI clock so I can keep the scroll bar synced to the music, and also so I can avoid making another timer if one is already running
from drywetmidi.
Internal MIDI clock of playback run with interval of 1 ms. With such small timer interval it's recommended to avoid some additional logic which can lead to playback latency. My suggestion right now is to create separate timer with interval of 10 ms for example and poll current time of playback.
But I'll think on adding some event that will be fired with the specified interval. For example, if you set interval to 100 ms, the event will be fired when playback position is advanced by 100 ms.
Thank you. I really appreciate that you share your experience and ask questions!
from drywetmidi.
I'm going to create special class for this purpose which will run another high-resolution timer and watch current time of the specified playbacks.
from drywetmidi.
Right. One more thing, is it possible to get the note information for inputdevices?
from drywetmidi.
is it possible to get the note information for inputdevices?
What do you mean? Receive note events via input device?
from drywetmidi.
Yep, but figured it out. You can get the input event and cast it to NoteOnEvent
, which has all the information I needed (and can't believe I didn't figure this out earlier...)
from drywetmidi.
Yes, that's how it should be done :)
I've added PlaybackCurrentTimeWatcher
class to watch current position of playback(s). This class is singleton in order to prevent too many high resolution timers are created (which is not good since it can affect whole system performance).
Small example:
PlaybackCurrentTimeWatcher.Instance.AddPlayback(playback, TimeSpanType.Midi);
PlaybackCurrentTimeWatcher.Instance.CurrentTimeChanged += OnCurrentTimeChanged;
PlaybackCurrentTimeWatcher.Instance.Start();
// ...
private static void OnCurrentTimeChanged(object sender, PlaybackCurrentTimeChangedEventArgs e)
{
foreach (var playbackTime in e.Times)
{
var playback = playbackTime.Playback;
var time = (MidiTimeSpan)playbackTime.Time;
Console.WriteLine($"Current time is {time}.");
}
}
In this example we watch current time of playback and request to report time in Midi
format which is ticks (and thus we cast received time to MidiTimeSpan
). You can set any desired time format and cast to corresponding implementation of the ITimeSpan
.
You can add multiple different playbacks to watch their current times. When you don't want to watch playback anymore remove it from the watcher:
PlaybackCurrentTimeWatcher.Instance.RemovePlayback(playback);
By default polling interval of watcher is 100 ms, but you can alter it:
PlaybackCurrentTimeWatcher.Instance.PollingInterval = TimeSpan.FromMilliseconds(50);
Please don't set too small intervals. I recommend to use the default value or something greater than 10 ms. Polling interval defines how often CurrentTimeChanged
event will be fired. If you want to pause firing the event, call Stop
method.
When your application is about to close, please dispose watcher to kill the internal timer:
PlaybackCurrentTimeWatcher.Instance.Dispose();
Thank you for making the library better! Waiting for your feedback on playback time watching.
from drywetmidi.
@ianespana Did you try playback watcher?
from drywetmidi.
@ianespana Please give me your feedback so we can proceed to either closing the issue or redesigning API.
from drywetmidi.
Sorry @melanchall , I've been very busy and haven't been able to try it yet. I will update my local version of the library today and give it a try. Thanks
from drywetmidi.
Works very well. Thanks a lot!
from drywetmidi.
Thank you for using the library! Feel free to open new issues or ask questions :)
from drywetmidi.
Related Issues (20)
- Remove all notes example from the README not working HOT 9
- Using wetdrymidi in C# project causes error CS0009
- InputDevice event listening crash HOT 2
- Crash when running in Unity on M2 MacBook HOT 3
- MidiDeviceException Internal error HOT 9
- Android Support
- Unity cannot exit after use HOT 10
- MidiClock sync problem HOT 6
- MIDI Tempo changes count returns 1 but the song has 6 tempo changes. HOT 1
- add il2cpp mode HOT 5
- CustomChunk no mididata throw error HOT 4
- CSharp Code Error HOT 2
- MIDI File returns error: InvalidMetaEventParameterValueException HOT 1
- Unable to send Note-On event to device HOT 8
- Cannot get track name to change HOT 10
- How to use DryWetMidi in Visual Basic (VS 2022) ? HOT 20
- Plans for MIDI 2.0 Support? HOT 2
- Skipping notes HOT 5
- Playback Loop=True skips empty steps in the end of a Pattern HOT 2
- Syncing multiple Playbacks HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drywetmidi.