Skip to content
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

Events for changing a chunk-event-list #41

Closed
FischertBilligheim opened this issue Oct 8, 2019 · 5 comments
Closed

Events for changing a chunk-event-list #41

FischertBilligheim opened this issue Oct 8, 2019 · 5 comments
Labels
feature request API changes required wont fix No API changes required
Projects

Comments

@FischertBilligheim
Copy link
Contributor

Would it be possible to implement an event-handling for changes in a event-list of a chunk?

I think for using the lists in a datagridview with data-binding this would be necessary.

Regards
Thomas

@melanchall
Copy link
Owner

Thomas,

Do you want EventsCollection to be something like ObservableCollection that can notify subscribers about collection changing?

@FischertBilligheim
Copy link
Contributor Author

Yes, I think so.
I‘m currently working on a midi-editor, based on your drywetmidi-library. I didn’t programmed since a lot of years, so a lot of things are unknown to me. I‘m currently using 2 datagridviews, in which I can show - in a human readable format - the events of a chunk. I implemented things like copy/paste/delete and Drag /drop. Also from one grid to the other. If an event of a chunk is deleted, and the other grid shows the same chunk, I need the possibility to be notified. (The Datagrids are encapsulated in a user-Control, I‘m currently filling the grids - and I‘m not using binding)

I yesterday did a test with binding: I added „..chunk.events.ToList()“ to the binding of a datagridview - the grid then shows 2 columns of the events: the type and the delta-time. But when I delete an entry of the events (from outside), the datagridview does not update....

I hope I could explane my needs 😉

@melanchall
Copy link
Owner

Thanks for explanation!

I think current implementation of EventsCollection shouldn't be changed since notifying about changes can cause performance penalties. Instead you should use another collection classes dumping all events into them before binding to UI controls.

For example, you read a MIDI file and want to use events collection of first track chunk as binding source for your DataGridView. In this case create dedicated collection class instance and copy all original events into it:

var originalEvents = trackChunk.Events;
var bindableCollection = new BindingList<MidiEvent>(originalEvents.ToList());

Then use bindableCollection as binding source for UI control. When you are done with MIDI data in your MIDI editor, just replace all original events with those contained in the bindableCollection:

originalEvents.Clear();
originalEvents.AddRange(bindableCollection);

Please let me know if it's worked.

@FischertBilligheim
Copy link
Contributor Author

Sure, this will work, but....

I‘m currently working directly at the chunks and events from DryWetMIDI. I‘m also deleting, merging and creating new chunks. To use own collections means to use the chunks-classes only for serializing the midi file. That‘s a pity. And by the way: I‘m also using playback etc....
But as I wrote: Sure, I can do that...,
Thanks a lot!
Thomas

@melanchall
Copy link
Owner

Although you've closed the issue, let me explain why you should create appropriate collections on your side.

Different frameworks requires different interfaces to support changes notification. WinForms works with IBindingList, WPF with INotifyCollectionChanged, some other frameworks requires another interfaces (probably those are not a part of standard .NET class library). So it's a bad idea to implement them all.

Also data binding is a concept related to MVVM, where there is a separation between data and UI. DryWetMIDI provides a layer that relates to data (model in terms of MVVM). Interaction with UI is absolutely up to user of the library.

@melanchall melanchall added feature request API changes required wont fix No API changes required labels Feb 2, 2020
@melanchall melanchall added this to Done in DryWetMIDI Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request API changes required wont fix No API changes required
Projects
DryWetMIDI
  
Done
Development

No branches or pull requests

2 participants