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

convert MidiEvent to data class #34

Closed
wants to merge 1 commit into from
Closed

Conversation

sed0
Copy link
Contributor

@sed0 sed0 commented May 2, 2023

#31
It's mentioned that the class is complicated but I feel like it's ok to make it a data class. I don't know why getters were used on some properties but I removed them, I'll get them back if needed

@sed0
Copy link
Contributor Author

sed0 commented May 2, 2023

I can also convert other classes to data classes but I haven't used the library that much and I don't know what classes to change

@atsushieno
Copy link
Owner

Thanks for this PR too!

At this state I have to say I'm rather negative to this change. Data class would mean semantic changes on equality like you suggested in the code, and that is not efficient for arrays which are of not fixed length. If I understand data class correctly, one guideline on whether a class should be a data class or not would be that if it is not efficiently comparable then it is probably not for data classes.

It is also a breaking change so I will have to make various changes to my apps. IF data classes bring in significant, not just nominal, improvements, then I would go for it though. But I wasn't given any proof so far.

I don't know why getters were used on some properties

I'm not familiar enough with how kotlin compilers and linkers work so correct me if wrong, but my idea was that those readonly fields cost extra space on memory while getters don't. (It was how .NET worked when I ported this library from C#.)

} else if (other.extraData != null) return false
if (extraDataOffset != other.extraDataOffset) return false
if (extraDataLength != other.extraDataLength) return false
if (statusByte != other.statusByte) return false
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rest of those fields are part of value so there is no need to compare them.

result = 31 * result + (extraData?.contentHashCode() ?: 0)
result = 31 * result + extraDataOffset
result = 31 * result + extraDataLength
result = 31 * result + statusByte
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

@sed0
Copy link
Contributor Author

sed0 commented May 3, 2023

It is also a breaking change so I will have to make various changes to my apps. IF data classes bring in significant, not just nominal, improvements, then I would go for it though. But I wasn't given any proof so far.

I guess I'll close the PR for now but I might get back to it later if I figure this out. Right now I feel like you are right and this class shouldn't be a data class.

I'm not familiar enough with how kotlin compilers and linkers work so correct me if wrong, but my idea was that those readonly fields cost extra space on memory while getters don't. (It was how .NET worked when I ported this library from C#.)

Yes, that's right. I just thought it's not that important here.

@sed0 sed0 closed this May 3, 2023
@atsushieno
Copy link
Owner

If you do not mind I would rather reopen the PR and leave it as is, it's better not have it hidden.

I just thought it's not that important here.

It is kind of :-) MIDI messages could be thousands on a song. Also IN CASE there are people who try to get closer to realtime MIDI processor, people would like to have MIDI buffers that never allocates smaller.

@sed0
Copy link
Contributor Author

sed0 commented May 4, 2023

If you do not mind I would rather reopen the PR and leave it as is, it's better not have it hidden.

Ok! I might return to it later

It is kind of :-) MIDI messages could be thousands on a song. Also IN CASE there are people who try to get closer to realtime MIDI processor, people would like to have MIDI buffers that never allocates smaller.

Thanks for the explanation!

@sed0 sed0 reopened this May 4, 2023
@atsushieno
Copy link
Owner

In my recent planned changes in ktmidi v0.6, MidiEvent becomes Midi1Message interface and there will be actually Midi1SimpleMessage data class and Midi1CompoundMessage non-data class. If that does not going to work well please let me know: #49

@sed0
Copy link
Contributor Author

sed0 commented Aug 12, 2023

looks fine to me!

@atsushieno
Copy link
Owner

Thanks. The changes in v0.6-brahch are now merged to the main tree. Closing this and #31.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants