Making Music Notes in Python
<p>I've got a project to make a sort of music synthesizer with python3. I've got to use numbers from stock data and create a player file and a file with my music class that will output notes to a .rra file with my play function. </p>

<p>m.play(D,3,2) Playing a D in the third octave for 2 beats.</p>

<p>I'm still really confused how my play function would work. To play a certain note at an octave I assume I would append the stock data numbers for as long as the note is supposed to play. I'm confused as how I would input this into code. </p>

<h1>Any help or tips at all would be appreciated.</h1>

<p>Here is the skeleton for my music class file and my player file:</p>

<p>I would play it with the command: "python3 player.py stock.dat | aplay"</p>

<h2>music.py</h2>

<p>class music:</p>

<pre><code>def __init__(self, infile):

    self.infile = infile
    self.beats = 4
    self.list = []
    fp = open(infile, 'r')
    for line in fp:
        self.list.append(eval(line))
    pass

def set_beat(self, x):
    self.beats = x

def header(self):
    print("RRA\n%%\n")

def play(self, note, octave, beats):
    pass

def __str__(self):
    s = "infile" + self.infile + ", Beats:" + self.beats
</code></pre>

<hr>

<h2>player.py</h2>

<pre><code>import sys
from music import Music

def main():

m = Music(sys.argv[1])

m.set_beat(0.25) # one beat is 0.25 seconds

m.header() #output the audio header

m.play("C",3,1) # play C in octave 3 for one beat

m.play("D",3,2) # play D in octave 3 for two beats

main()
</code></pre>
