Skip to content

Instantly share code, notes, and snippets.

@msroot
Created February 13, 2016 01:29
Show Gist options
  • Select an option

  • Save msroot/9b1d998884ed44ca2926 to your computer and use it in GitHub Desktop.

Select an option

Save msroot/9b1d998884ed44ca2926 to your computer and use it in GitHub Desktop.
# Define Music:
# Vocal or instrumental sounds (or both) combined in such a way as to produce beauty of form, harmony, and expression of emotion.
class Music
has_many :sounds
has_many :notes , through: :sounds
sequences_of_emotions = []
def good user
sequences_of_emotions.select { |e| e == user.definition_of(Music, :good) }
end
end
class Sound
has_many :notes
end
class Note
has_many :sequences
end
class Vocal < Sound
end
class User
DEFINITIONS = {
music: {
good: []
}
}
def definition_of klass, type
DEFINITIONS[klass.downcase][type]
end
end
# a user can say:
#
# Play some good music
#
# 1. play = action the computer has to execute
# 2. some = the range
# 3. good = a selection based on the user for the object(music)
# 4. music = the subject
# the only hard to explain here is the "good" because the good based on the expectation we want.
# what is good music? and what is good in general?
# good: to be desired or approved of.
# So we should define what is good for us based on the previus examples
# How can u define good? what music is do so will do "good" to me?
# IF: i accept these type of sequences and i will hear them it is good for me
@victornava
Copy link
Copy Markdown

Here is another way to do this. Let's say we want to compose a song using only
the piano. So we start by setting some parameters like:

- Define the length of a song
- Define the frequency range
- Define the mood of the song
- Define the speed of the song
- Define the max difference between thehighest and lowest note

Then we tell the computer:

Make every possible combination of notes sequences that match these parameters.

A piano song is a sequence of notes and spaces. So it is easy to represent
using an array of numbers. A piano for instance has 88 keys, you could
represent a song in an array:

here how you make random piano song:

notes = 100.times.map { (0..88).to_a.sample } => [79, 25, 42, 40, 58, 77, 55,
36, 25, 39, 44, 77, 5, 51, 37, 18, 22, 52, 60, 21, 57, 8, 3, 33, 40, 77, 77,
30, 61, 5, 53, 6, 21, 77, 9, 74, 55, 87, 13, 87, 21, 43, 23, 39, 72, 61, 32,
26, 34, 83, 29, 30, 63, 81, 21, 80, 88, 19, 55, 5, 0, 29, 4, 51, 63, 52, 55, 9,
55, 73, 67, 4, 68, 55, 6, 37, 41, 33, 36, 45, 82, 51, 75, 58, 66, 29, 68, 29,
58, 20, 85, 70, 56, 3, 8, 19, 87, 51, 44, 47]

then play it:

Piano.play(notes, at: 1_note_per_second)

You can generate all possible 100-note songs with a simple method:

all_possible_songs = (0..88).to_a.combination(100)

But that would take a long long time. Because regular computers today are too
slow to do it. In a few years this would be possible to do on your laptop.

Once this happens, we would sit down and just select what we like.

The first result of the program would be all_possible_songs minus the onces
that don't match the initial parameters you set.

You would listen to the first few seconds of a song and tell the computer if
you like it or not.

Every time you do this a program will filter out the songs you don't like from
the result, so you would go from the initial million to half a million, then a
quarter and eight. Until you find a song or a several song you like.

Once you have a few songs you like, you tell the computer now make more songs
like these ones. And repeat the process.

The main thing here is:

When computers are super fast and software smart, it will be possible to genera
every single song that you can fit in 5 minutes, and then select the ones that
are similar to what humans like. Every single one.

Sounds crazy but it is possible in theory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment