# scale playing

from math import floor
from numpy import linspace, append, zeros
from scipy.io.wavfile import write

freqSamp,rptsList,freqList,zeroList=44100,[],[],[]

ionianET=[261.63,293.66,329.63,349.23,392.00,440.00,493.88,523.25]

for note in ionianET:
    flNote=floor(freqSamp/note)
    flNote=flNote if flNote%2==0 else flNote-1
    rptsList.append(flNote)
    freqList.append(floor(note))
    zeroList.append(freqSamp-floor(note)*flNote)
    
print(rptsList,freqList,zeroList)

scale=[]

# triangle oscillator and padding

for count in range(8):

    halfRpts=rptsList[count]//2

    firstHalf=linspace(-1.0,1.0,halfRpts,False).astype(float)
    lastHalf=linspace(1.0,-1.0,halfRpts,False).astype(float)
    triData=append(firstHalf,lastHalf)

    rpts=freqList[count]-1
    triNote=triData
    while rpts>0:
        triNote=append(triNote,triData)
        rpts=rpts-1
    
    scale=append(scale,triNote)
    
    padding=zeros(zeroList[count]).astype(float)
    
    scale=append(scale,padding)
    
write('scale.wav',freqSamp,scale)