Some notes I jotted down while perusing a first year music theory book and fiddling around on a keyboard the last couple of days. I hope the formatting helps make the length bearable, I'm just trying to put everything on the table I've found that we could possibly work with.
As for the essential task of constructing a melody that to some degree
euphonic, here are a few musical ideas that we could consider:
Tonality: the melody should create some sort of pull towards a
specific pitch (the "tonic"). This can be accomplished by either one or
a combination of the following methods: 1) simply referencing the
tonic more often than any other pitch, 2) placing the tonic at key
points within the passage (such at the beginning, end or any strong
metrical point (e.g., downbeats), 3) using other pitches that support
and reinforce the tonic harmonically (such as the perfect 5th above or
perfect 4th below), or 4) tying pitches that are one step away (usually
below) from the tonic in shorter rhythmic phrases (such as a sixteenth
note immediately preceding it
There is risk of the melody becoming overly tonal, so it would also be
good to set restrictions, perhaps via a counter, that would make sure
that a note isn't used too much in any given segment of the four bar
phrase.
Creating a less tonal melody may be effective in expressing confusion,
though it may only succeed in stripping it of any emotional connotations
whatsoever. Good old trial and error should serve us well here.
Intervals: the use of consonant and dissonant intervals may be an
easy way to express peace and struggle accordingly, though these two
feelings don't correspond directly with any of our mood
parameters (damn human psyche...). Regardless, it'll probably work fine
as long as we have
other factors to reinforce them. When choosing the next note in the
series, the algorithm could adjust the probability of which interval is
used according to the location
of the preceding note and the current happiness level (certain intervals
may be exclusively reserved for certain emotional state).
Larger intervals create more space (which in turn yields clarity and placidity) while
smaller intervals tend to muddle things up. This could work well for our
confusion parameter.
Here is a little schematic of the relative consonance / dissonance of the most commonly used intervals:
+ 0 half-steps: strongly consonant
+ 1 half-step: strongly dissonant
+ 2 half-steps: mildly dissonant
+ 3 half-steps: consonant
+ 4 half-steps: consonant
+ 5 half-steps: strongly consonant
+ 6 half-steps: dissonant
+ 7 half-steps: strongly consonant
+ 8 half-steps: consonant
+ 9 half-steps: consonant
+ 10 half-steps: mildly dissonant
+ 11 half-steps: strongly dissonant
+ 12 half-steps: strongly consonant
Phrasing:
As far as I can tell, the easiest way to frame the melody as one
complete thought would be to use the same intervallic distance at the
beginning and end of the four bar phrase. This will give it a sense of
finality, which could be something we reserve for more logical emotional
states.
In order to weave together the individual measures, we could insert
"cadences" (rhythmic and/or tonal punctuation) at the end of each, and
have it so the first three are less conclusive than the final. For
example: the first three measures could end with an eighth note on the
perfect 4th or 5th, while the final measure ends with a quarter note on
the tonic.
The contour of the melodic line can create a feeling of tension / motion
(excitement) if going up and relaxation (boredom?) it going down.
Dynamic changes can also help create a sense of motion, though I was
thinking it'd be best to keep them gradual so that we can simply modify a
general direction
The rhythm and melody of the first measure could be used as a template
for the other three, so that (as you suggested) they are in some way
related. I'm gonna need to spend some more time studying the concept of
variation before suggesting an algorithmic method to emulate it, but in
any case we're gonna need some way to store information about the first
measure so that it can be accessed while generating the others.
Once we can get the program to output a melody with solid structure,
tweaking its tempo, timbre and octave placement should be a fairly easy
way to signal the different moods.
Excited / Relaxed (tempo (I'm thinking 90 - 120 bpm is a good range), articulation)
Random / Logical (distortion / bitcrusher)
If any of this needs clarifying, let me know. I'm just getting my head around a lot of this music theory jargon myself. Fortunately I've found a pretty good reference, so I could probably elaborate if it'd help.