What is a general way to generate all the notes within a key
I'm designing a piece of software in python to aid me in composition and to make useful suggestions while I'm playing. Currently a key is defined in the following way:
noteDict = {"R":"C", #root
"m2":"Db", #minor 2nd
"M2":"D", #major 2nd
"m3":"Eb", #etc
"M3":"E",
"P4":"F",
"A4":"F#",
"D5":"Gb",
"P5":"G",
"A5":"G#",
"m6", "Ab",
"M6", "A",
"m7", "Bb",
"M7", "B"}
#stores noteDict, and adds entries for notes in a different format:
#ex: knows that a m6 is the same as a b13 and a D5 is the same as a b5
C = key(noteDict)
This works as intended, however it would be nice to be able to have a set of rules that define how a key is constructed as opposed to hand coding it all. Obvious rules exist such as "Augmented 4th is the Perfect 4th with a sharp", however I'd still need a way to generate the base scale (ie in C major: R M2 M3 P4... - C D E F...) and then apply the modifications to the base scale.
An obvious way to do this is to maintain a table of intervals based on semitones, so if you are told a root (such as C), you could add 3 semitones to the root to reach the minor 3rd (C -> Db -> D -> Eb).
The problem with this method arises when dealing with keys such as Cb major. Finding the correctly spelled minor third of Cb would add three semitones and spit out D instead of the correct Ebb. How could I generate a correctly spelled noteDict for an arbitrary key?
python
|
show 2 more comments
I'm designing a piece of software in python to aid me in composition and to make useful suggestions while I'm playing. Currently a key is defined in the following way:
noteDict = {"R":"C", #root
"m2":"Db", #minor 2nd
"M2":"D", #major 2nd
"m3":"Eb", #etc
"M3":"E",
"P4":"F",
"A4":"F#",
"D5":"Gb",
"P5":"G",
"A5":"G#",
"m6", "Ab",
"M6", "A",
"m7", "Bb",
"M7", "B"}
#stores noteDict, and adds entries for notes in a different format:
#ex: knows that a m6 is the same as a b13 and a D5 is the same as a b5
C = key(noteDict)
This works as intended, however it would be nice to be able to have a set of rules that define how a key is constructed as opposed to hand coding it all. Obvious rules exist such as "Augmented 4th is the Perfect 4th with a sharp", however I'd still need a way to generate the base scale (ie in C major: R M2 M3 P4... - C D E F...) and then apply the modifications to the base scale.
An obvious way to do this is to maintain a table of intervals based on semitones, so if you are told a root (such as C), you could add 3 semitones to the root to reach the minor 3rd (C -> Db -> D -> Eb).
The problem with this method arises when dealing with keys such as Cb major. Finding the correctly spelled minor third of Cb would add three semitones and spit out D instead of the correct Ebb. How could I generate a correctly spelled noteDict for an arbitrary key?
python
4
I am afraid your question is too musical. Could you maybe describe in less musical terms what it is you are trying to do?
– Ev. Kounis
Feb 8 '18 at 17:13
For example, "Augmented 4th is the Perfect 4th with a sharp" is not obvious at all; far from it.
– Ev. Kounis
Feb 8 '18 at 17:16
Since the code cannot know anything without you telling it the proper instructions, I would suggest converting these musical "rules" into code. Python is great for this since you can useif
,and
,in
to define such rules in a few lines... but not many people on SO know the details of these rules to advise properly on how to proceed with this.
– JacobIRR
Feb 8 '18 at 17:32
Unfortunately, this is a musical logic question, so there's not much I can do to disentangle that! Is there a better place to ask something like this?
– Michael Hackman
Feb 8 '18 at 18:18
1
Think about what constitutes "correctly spelled" in the eyes of a computer. You have to write code that says something like: "If a letter is already listed in a key, use the next letter in line and flatten (or sharpen) it". Trying to write this code and then posting that with an error or question is the best way to get help since the question is currently trapped in the land of rules for sheet music and not programming specifics.
– JacobIRR
Feb 8 '18 at 18:37
|
show 2 more comments
I'm designing a piece of software in python to aid me in composition and to make useful suggestions while I'm playing. Currently a key is defined in the following way:
noteDict = {"R":"C", #root
"m2":"Db", #minor 2nd
"M2":"D", #major 2nd
"m3":"Eb", #etc
"M3":"E",
"P4":"F",
"A4":"F#",
"D5":"Gb",
"P5":"G",
"A5":"G#",
"m6", "Ab",
"M6", "A",
"m7", "Bb",
"M7", "B"}
#stores noteDict, and adds entries for notes in a different format:
#ex: knows that a m6 is the same as a b13 and a D5 is the same as a b5
C = key(noteDict)
This works as intended, however it would be nice to be able to have a set of rules that define how a key is constructed as opposed to hand coding it all. Obvious rules exist such as "Augmented 4th is the Perfect 4th with a sharp", however I'd still need a way to generate the base scale (ie in C major: R M2 M3 P4... - C D E F...) and then apply the modifications to the base scale.
An obvious way to do this is to maintain a table of intervals based on semitones, so if you are told a root (such as C), you could add 3 semitones to the root to reach the minor 3rd (C -> Db -> D -> Eb).
The problem with this method arises when dealing with keys such as Cb major. Finding the correctly spelled minor third of Cb would add three semitones and spit out D instead of the correct Ebb. How could I generate a correctly spelled noteDict for an arbitrary key?
python
I'm designing a piece of software in python to aid me in composition and to make useful suggestions while I'm playing. Currently a key is defined in the following way:
noteDict = {"R":"C", #root
"m2":"Db", #minor 2nd
"M2":"D", #major 2nd
"m3":"Eb", #etc
"M3":"E",
"P4":"F",
"A4":"F#",
"D5":"Gb",
"P5":"G",
"A5":"G#",
"m6", "Ab",
"M6", "A",
"m7", "Bb",
"M7", "B"}
#stores noteDict, and adds entries for notes in a different format:
#ex: knows that a m6 is the same as a b13 and a D5 is the same as a b5
C = key(noteDict)
This works as intended, however it would be nice to be able to have a set of rules that define how a key is constructed as opposed to hand coding it all. Obvious rules exist such as "Augmented 4th is the Perfect 4th with a sharp", however I'd still need a way to generate the base scale (ie in C major: R M2 M3 P4... - C D E F...) and then apply the modifications to the base scale.
An obvious way to do this is to maintain a table of intervals based on semitones, so if you are told a root (such as C), you could add 3 semitones to the root to reach the minor 3rd (C -> Db -> D -> Eb).
The problem with this method arises when dealing with keys such as Cb major. Finding the correctly spelled minor third of Cb would add three semitones and spit out D instead of the correct Ebb. How could I generate a correctly spelled noteDict for an arbitrary key?
python
python
edited Dec 28 '18 at 14:46
Dima Rostopira
3,4503252
3,4503252
asked Feb 8 '18 at 17:10
Michael HackmanMichael Hackman
129213
129213
4
I am afraid your question is too musical. Could you maybe describe in less musical terms what it is you are trying to do?
– Ev. Kounis
Feb 8 '18 at 17:13
For example, "Augmented 4th is the Perfect 4th with a sharp" is not obvious at all; far from it.
– Ev. Kounis
Feb 8 '18 at 17:16
Since the code cannot know anything without you telling it the proper instructions, I would suggest converting these musical "rules" into code. Python is great for this since you can useif
,and
,in
to define such rules in a few lines... but not many people on SO know the details of these rules to advise properly on how to proceed with this.
– JacobIRR
Feb 8 '18 at 17:32
Unfortunately, this is a musical logic question, so there's not much I can do to disentangle that! Is there a better place to ask something like this?
– Michael Hackman
Feb 8 '18 at 18:18
1
Think about what constitutes "correctly spelled" in the eyes of a computer. You have to write code that says something like: "If a letter is already listed in a key, use the next letter in line and flatten (or sharpen) it". Trying to write this code and then posting that with an error or question is the best way to get help since the question is currently trapped in the land of rules for sheet music and not programming specifics.
– JacobIRR
Feb 8 '18 at 18:37
|
show 2 more comments
4
I am afraid your question is too musical. Could you maybe describe in less musical terms what it is you are trying to do?
– Ev. Kounis
Feb 8 '18 at 17:13
For example, "Augmented 4th is the Perfect 4th with a sharp" is not obvious at all; far from it.
– Ev. Kounis
Feb 8 '18 at 17:16
Since the code cannot know anything without you telling it the proper instructions, I would suggest converting these musical "rules" into code. Python is great for this since you can useif
,and
,in
to define such rules in a few lines... but not many people on SO know the details of these rules to advise properly on how to proceed with this.
– JacobIRR
Feb 8 '18 at 17:32
Unfortunately, this is a musical logic question, so there's not much I can do to disentangle that! Is there a better place to ask something like this?
– Michael Hackman
Feb 8 '18 at 18:18
1
Think about what constitutes "correctly spelled" in the eyes of a computer. You have to write code that says something like: "If a letter is already listed in a key, use the next letter in line and flatten (or sharpen) it". Trying to write this code and then posting that with an error or question is the best way to get help since the question is currently trapped in the land of rules for sheet music and not programming specifics.
– JacobIRR
Feb 8 '18 at 18:37
4
4
I am afraid your question is too musical. Could you maybe describe in less musical terms what it is you are trying to do?
– Ev. Kounis
Feb 8 '18 at 17:13
I am afraid your question is too musical. Could you maybe describe in less musical terms what it is you are trying to do?
– Ev. Kounis
Feb 8 '18 at 17:13
For example, "Augmented 4th is the Perfect 4th with a sharp" is not obvious at all; far from it.
– Ev. Kounis
Feb 8 '18 at 17:16
For example, "Augmented 4th is the Perfect 4th with a sharp" is not obvious at all; far from it.
– Ev. Kounis
Feb 8 '18 at 17:16
Since the code cannot know anything without you telling it the proper instructions, I would suggest converting these musical "rules" into code. Python is great for this since you can use
if
, and
, in
to define such rules in a few lines... but not many people on SO know the details of these rules to advise properly on how to proceed with this.– JacobIRR
Feb 8 '18 at 17:32
Since the code cannot know anything without you telling it the proper instructions, I would suggest converting these musical "rules" into code. Python is great for this since you can use
if
, and
, in
to define such rules in a few lines... but not many people on SO know the details of these rules to advise properly on how to proceed with this.– JacobIRR
Feb 8 '18 at 17:32
Unfortunately, this is a musical logic question, so there's not much I can do to disentangle that! Is there a better place to ask something like this?
– Michael Hackman
Feb 8 '18 at 18:18
Unfortunately, this is a musical logic question, so there's not much I can do to disentangle that! Is there a better place to ask something like this?
– Michael Hackman
Feb 8 '18 at 18:18
1
1
Think about what constitutes "correctly spelled" in the eyes of a computer. You have to write code that says something like: "If a letter is already listed in a key, use the next letter in line and flatten (or sharpen) it". Trying to write this code and then posting that with an error or question is the best way to get help since the question is currently trapped in the land of rules for sheet music and not programming specifics.
– JacobIRR
Feb 8 '18 at 18:37
Think about what constitutes "correctly spelled" in the eyes of a computer. You have to write code that says something like: "If a letter is already listed in a key, use the next letter in line and flatten (or sharpen) it". Trying to write this code and then posting that with an error or question is the best way to get help since the question is currently trapped in the land of rules for sheet music and not programming specifics.
– JacobIRR
Feb 8 '18 at 18:37
|
show 2 more comments
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48691102%2fwhat-is-a-general-way-to-generate-all-the-notes-within-a-key%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48691102%2fwhat-is-a-general-way-to-generate-all-the-notes-within-a-key%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
4
I am afraid your question is too musical. Could you maybe describe in less musical terms what it is you are trying to do?
– Ev. Kounis
Feb 8 '18 at 17:13
For example, "Augmented 4th is the Perfect 4th with a sharp" is not obvious at all; far from it.
– Ev. Kounis
Feb 8 '18 at 17:16
Since the code cannot know anything without you telling it the proper instructions, I would suggest converting these musical "rules" into code. Python is great for this since you can use
if
,and
,in
to define such rules in a few lines... but not many people on SO know the details of these rules to advise properly on how to proceed with this.– JacobIRR
Feb 8 '18 at 17:32
Unfortunately, this is a musical logic question, so there's not much I can do to disentangle that! Is there a better place to ask something like this?
– Michael Hackman
Feb 8 '18 at 18:18
1
Think about what constitutes "correctly spelled" in the eyes of a computer. You have to write code that says something like: "If a letter is already listed in a key, use the next letter in line and flatten (or sharpen) it". Trying to write this code and then posting that with an error or question is the best way to get help since the question is currently trapped in the land of rules for sheet music and not programming specifics.
– JacobIRR
Feb 8 '18 at 18:37