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

[feature] Constructor with defaults. #69

Closed
p-groarke opened this issue Mar 28, 2020 · 0 comments · Fixed by #90
Closed

[feature] Constructor with defaults. #69

p-groarke opened this issue Mar 28, 2020 · 0 comments · Fixed by #90
Assignees
Labels
feature new feature request

Comments

@p-groarke
Copy link
Contributor

Hi, I hope you are well and good amidst the current pandemic.

I've been hitting a minor snag when trying to store mx::api types in various const/global containers. It would be nice if PitchData offered a flexible value constructor to remedy this.

For example:
PitchData(Step step = Step::c, int alter = 0, double cents = 0.0, Accidental c = Accidental::none, bool = false, bool = false, bool = false, bool = false, int octave = 4);

This would enable a user to create pitches like this: PitchData p{Step::c, -1}; which is nice.

A real world use case, I am building an unordered_map to map a root to a mx::api::KeyData fifth.

namespace mx {
using namespace api;
}

namespace std {
template <>
struct hash<mx::PitchData> {
	constexpr inline size_t operator()(const mx::PitchData& p) const {
		size_t h1 = size_t(p.step) << 32;
		size_t h2 = size_t(p.alter);
		return h1 ^ h2;
	}
};
} // namespace std


namespace {
std::unordered_map<mx::PitchData, int> root_to_key_circle {
    { mx::PitchData{/* you cannot do that :( */ }, -1 },
    { mx::PitchData{/* you cannot do that :( */ }, 0 },
    { mx::PitchData{/* you cannot do that :( */ }, 1 },
// etc
};
} // namespace

Now, you may want to have different or other types of constructors, but the general idea is the same. It would be nice to be able to construct a PitchData with a few arguments.

Take care and stay safe!

@webern webern self-assigned this May 7, 2020
@webern webern added the feature new feature request label May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature new feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants