python-midi icon indicating copy to clipboard operation
python-midi copied to clipboard

How to copy Event object?

Open anath2 opened this issue 10 years ago • 2 comments

I want to extract a part of a midi file and save it on a file

I am trying to copy events from pattern to another. But it seems deepcopy and copy aren't supported.

anath2 avatar Jun 24 '14 10:06 anath2

Interesting. The non-meta events (those that inherit midi.Event) already have their own copy function, but meta events do not. Meanwhile copy.copy does work for me on a significant number of events but stumbles on some of the ones with special getters/setters. (I've read that messing with __getAttr__ and its relatives can cause weird copy problems because the copy module doesn't immediately init objects when trying to duplicate them, but I don't have the expertise to deduce quickly whether that's the problem or not.)

So ultimately neither copying method currently covers everything. I do think providing copy/deepcopy support would be useful and would only require adding some pretty simple helper methods.

tdhsmith avatar Jun 27 '14 22:06 tdhsmith

Hi guys! I can't copy a simple NoteOnEvent object. Could you add a copy method for that? Or do you want me to submit a patch? I suffer from lack of possibility to copy events and in effect - patterns.

The jobs I want to do with midi is opening a midi file, making changes, and writing them back to disk. But if I write 2 files made from the same source, they are bogus, as events are common to both files.

jarekczek avatar Feb 04 '15 20:02 jarekczek