Jump to content

Any computer programmers?


Recommended Posts

I need a musical combination lock written. The idea is that you see the starting and ending pitches, and their frequencies, and then a bunch of pitches without numbers, which have to be converted to their equal temper frequencies, and then put in the correct order based on the mathematical operations given in the equation. When the equation (based on the numbers) is balanced, the lock plays the tune in the correct order, and opens to reveal a message. It's not a physical lock, just a computer lock, like a password.

It looks something like this, in its bare-bones format:

G# (821) - ___ + ___ - ___ + ___ - ___ + ___ - ___ = A (440)

B4 C#5 D5 E5 F#4 G4 Ab4

Basically, it's no different than substituting a number for a letter, say X or Y, except these letters are pitches. And then at the end, it plays the melody and reveals the locked message (which should be customizable).

How does one go about programming something like this?

Link to comment
Share on other sites

Guest JohnGalt

Hm, without actually writing this program, I don't know if my idea will work, but I think it could be done with something like:

(using Perl expressions here, only language I know well)

$a = startingpitchvalue (a number)

$i = 440 (ending pitch)

Generate six random numbers within the parameters of acceptable pitches, and only divisble by something like 10 to make it easy.

Add the random numbers in random order, to the first number.

Take the result and subtract 400 if it's larger, or subtract it from 400 if it's smaller. That will be the last pitch besides A.

As you're doing that, assign each pitch to a variable, let's say a hash. So:

Key 1 = starting pitch

Key 2 = random pitch 1

Key 3 = random pitch 2

Key 4 = random pitch 3

Key 5 = random pitch 4

Key 6 = random pitch 5

Key 7 = random pitch 6

Key 8 = random pitch 7

Key 9 = ending pitch

Now, save that to a document. Create a subroutine to load the hash. Create another subroutine to convert inputted frequencies into another hash, like before. One last subroutine will check the two hashes against each other, and, if there's a match, do what you want it to do, otherwise, report an error and start over.

This is just my take on it, there's probably a thousand ways to do it.

[EDIT] Duh, forgot to mention. You will, at some point, need the program to output the pitches generated, so you know what they are.

Link to comment
Share on other sites

You could use something like Pure Data, or Max/MSP to do this. If you do, then half the battle is done already for you in dealing with playback etc.

Display is not pretty by default (you can play around with it quite a lot though), but then that all depends on what you want the program for...

Link to comment
Share on other sites

Qbasic is your best bet for something like this. I managed to write a Beatles trivia game that played bits of songs and you had to guess what they were. The only limitations, would be that getting from a variable to the code needed to make the music work would take a long time.

Link to comment
Share on other sites

  • 1 month later...

This is an odd idea, but it does pose some interesting problems...

So you would have the starting and ending notes and frequencies, and then only a list of frequencies for the remaining notes in a list below them, right? And then a person who puts them in order correctly hears the song and is let in. I hope i understand this correctly, because im thinking about using this to get my programming skills focused before the semester starts.

One point however, your mathmatical equation, with only pluses and minuses, would not work as you intend it to work. I could easily switch any two numbers being added, or i could switch any two numbers being subtracted, and i would still get the desired 440.

Maybe, instead of dealing with mathmatics, just have each user program a specific melodic fragment and then the user must input the missing pieces. You could also do this with chords. A user creates a chord (lets say, G4 B4 D5 F#5 A5, or G maj 9) and then the user inserts the notes in his chord.

Link to comment
Share on other sites

This sounds like a really cool idea. In Java, if I were to write it, I would use the JFugue API. It can be found at http://www.jfugue.org and it's really useful. I've used it for projects before. I may just do something like this if I have the time. One question: equal tempered frequencies are all irrational except for A, which is always 440*2^n where n is an integer. How much precision would you want? Keep in mind that, although for higher frequencies the units place would probably be sufficient, as pitch gets lower, the frequencies of consecutive notes get closer together.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...