So I'm writing a code that imports pygame to play files of music notes. I set each note to a button, 24 notes for 24 buttons. However, the program will also have four more buttons: "Record", "Stop", "Playback", and "Quit". when the record button is clicked, it will append the file name to a songlist. Then the stop button will be pressed to terminate the record function. the songlist will then be played using the playback by having an index = 0 and in the function it will have:
while index < len(songList):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+songList[index])
mixer.music.play(0,0.0)
index+=1
The function will go through each element of the list and play each note.
So my problem here, is creating the record function. I need to have it so that it knows when a note button is clicked so that it can append a name to the songlist. So can I write a code that tells whether or not a button is clicked or not.
for example in pseuodocode...
if "C# Button is clicked":
note = 'Csharp.mp3'
songList.append(note)
if "D Button is clicked":
note = 'D.mp3'
songList.append(note)
how would I write in actual coding ( if "D Button is clicked")
when each note button is pressed, it runs this function:
def playC(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[0])
mixer.music.play(0,0)
note = '2C.mp3'
Each note button will have this format but with the note and the filename different of course. a friend of mine gave me the idea to set maybe a dummy statement such as
self.C = 'Go' after the mixer.music.play function. So that I would write in the Record function....
if self.C = 'Go':
songList.append(note)
Any ideas? this is the actual code that I have so far... it's not quite finished yet and I've been commenting stuff out as well.
from tkinter import *
from pygame import *
NOTELIST = ['2C.mp3', '2C#.mp3', '2D.mp3', '2D#.mp3', '2E.mp3', '2F.mp3', '2F#.mp3', '2G.mp3', '2G#.mp3', '2A.mp3', '2A#.mp3', '2B.mp3', \
'3C.mp3', '3C#.mp3', '3D.mp3', '3D#.mp3', '3E.mp3', '3F.mp3', '3F#.mp3', '3G.mp3', '3G#.mp3', '3A.mp3', '3A#.mp3', '3B.mp3']
KEY = ['z', 's', 'x', 'd', 'c', 'v', 'g', 'b', 'h', 'n', 'j', 'm',\
'q', '2', 'w', '3', 'e', 'r', '5', 't', '6', 'y', '7', 'u']
class Editor:
def __init__(self):
#create the main window
self.main_window = Tk()
self.main_window.title("Music")
#create frames
self.top_frame = Frame(self.main_window)
self.middle_frame = Frame(self.main_window)
self.octave1 = Frame(self.main_window)
self.octave2 = Frame(self.main_window)
self.bottom_frame = Frame(self.main_window)
#Create widgest
#create label for top frame
self.Label = Label(self.top_frame, text = "Hit Record and record a tune")
#pack label
self.Label.pack(side = "top")
#create buttons for middle frame
## self.Record = Button(self.middle_frame, text = "Record", command = self.Record)
## self.Stop = Button(self.middle_frame, text = "Stop", command = self.Stop)
## self.Play = Button(self.middle_frame, text = "Play", command = self.Playback)
## self.Quit = Button(self.middle_frame, text = "Quit", command = self.main_window.destroy)
#Pack buttons
## self.Record.pack(side = "left")
## self.Stop.pack(side = "left")
## self.Play.pack(side = "left")
## self.Quit.pack(side = "left")
#create buttons for keyboard octave 1
self.C = Button(self.octave1, text = "C", command = self.playC)
self.Csharp = Button(self.octave1, text = "C#", command = self.playCsharp)
self.D = Button(self.octave1, text = "D", command = self.playD)
self.Dsharp = Button(self.octave1, text = "D#", command = self.playDsharp)
self.E = Button(self.octave1, text = "E", command = self.playE)
self.F = Button(self.octave1, text = "F", command = self.playF)
self.Fsharp = Button(self.octave1, text = "F#", command = self.playFsharp)
self.G = Button(self.octave1, text = "G", command = self.playG)
self.Gsharp = Button(self.octave1, text = "G#", command = self.playGsharp)
self.A = Button(self.octave1, text = "A", command = self.playA)
self.Asharp = Button(self.octave1, text = "A#", command = self.playAsharp)
self.B = Button(self.octave1, text = "B", command = self.playB)
self.C.pack(side='left')
self.Csharp.pack(side='left')
self.D.pack(side='left')
self.Dsharp.pack(side='left')
self.E.pack(side='left')
self.F.pack(side='left')
self.Fsharp.pack(side='left')
self.G.pack(side='left')
self.Gsharp.pack(side='left')
self.A.pack(side='left')
self.Asharp.pack(side='left')
self.B.pack(side='left')
#create buttons for keyboard octave 2
self.octC = Button(self.octave2, text = "C", command = self.play2C)
self.octCsharp = Button(self.octave2, text = "C#", command = self.play2Csharp)
self.octD = Button(self.octave2, text = "D", command = self.play2D)
self.octDsharp = Button(self.octave2, text = "D#", command = self.play2Dsharp)
self.octE = Button(self.octave2, text = "E", command = self.play2E)
self.octF = Button(self.octave2, text = "F", command = self.play2F)
self.octFsharp = Button(self.octave2, text = "F#", command = self.play2Fsharp)
self.octG = Button(self.octave2, text = "G", command = self.play2G)
self.octGsharp = Button(self.octave2, text = "G#", command = self.play2Gsharp)
self.octA = Button(self.octave2, text = "A", command = self.play2A)
self.octAsharp = Button(self.octave2, text = "A#", command = self.play2Asharp)
self.octB = Button(self.octave2, text = "B", command = self.play2B)
self.octC.pack(side='left')
self.octCsharp.pack(side='left')
self.octD.pack(side='left')
self.octDsharp.pack(side='left')
self.octE.pack(side='left')
self.octF.pack(side='left')
self.octFsharp.pack(side='left')
self.octG.pack(side='left')
self.octGsharp.pack(side='left')
self.octA.pack(side='left')
self.octAsharp.pack(side='left')
self.octB.pack(side='left')
#create legend in bottom frame
## self.canvas = Canvas(width = 1000, height = 500)
## image = PhotoImage(file = "keyboard.gif")
## self.canvas.create_image(500,250, image = image)
## self.canvas.pack()
#pack Frames
self.top_frame.pack()
self.middle_frame.pack()
self.bottom_frame.pack()
self.octave1.pack()
self.octave2.pack()
mainloop()
##
##
##
def Record(self):
def Stop(self):
def Playback(self):
def playC(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[0])
mixer.music.play(0,0)
note = '2C.mp3'
def playCsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[1])
mixer.music.play(0,0)
note = '2C#.mp3'
def playD(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[2])
mixer.music.play(0,0)
note = '2D.mp3'
def playDsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[3])
mixer.music.play(0,0)
note = '2D#.mp3'
def playE(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[4])
mixer.music.play(0,0)
note = '2E.mp3'
def playF(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[5])
mixer.music.play(0,0)
note = '2F.mp3'
def playFsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[6])
mixer.music.play(0,0)
note = '2G.mp3'
def playG(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[7])
mixer.music.play(0,0)
note = '2G.mp3'
def playGsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[8])
mixer.music.play(0,0)
note = '2G#.mp3'
def playA(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[9])
mixer.music.play(0,0)
note = '2A.mp3'
def playAsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[10])
mixer.music.play(0,0)
note = '2A#.mp3'
def playB(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[11])
mixer.music.play(0,0)
note = '2B.mp3'
def play2C(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[12])
mixer.music.play(0,0)
def play2Csharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[13])
mixer.music.play(0,0)
def play2D(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[14])
mixer.music.play(0,0)
def play2Dsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[15])
mixer.music.play(0,0)
def play2E(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[16])
mixer.music.play(0,0)
def play2F(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[17])
mixer.music.play(0,0)
def play2Fsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[18])
mixer.music.play(0,0)
def play2G(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[19])
mixer.music.play(0,0)
def play2Gsharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[20])
mixer.music.play(0,0)
def play2A(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[21])
mixer.music.play(0,0)
def play2Asharp(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[22])
mixer.music.play(0,0)
def play2B(self):
mixer.init()
mixer.music.load("C:/Python32/Python Programs/NEW FINAL PROJECT/notes/"+NOTELIST[23])
mixer.music.play(0,0)
mygui = Editor()