A downloadable game

Music Player

Project Description

A simple Music player that can play music layer by layer. 

Assignment Rubrics

  • 3 points - describe how to use/play your instrument in comments at the top of your code
  • 5 points - use at least 5 sounds (through audio files, audio waves, or sound envelopes)
  • 2 points - have a visual component that changes depending on what sounds are playing
  • Extra Credit (1 point) - use more than 5 sounds
  • Extra Credit (1 point) - add more interesting controls than simply "press some key to play the sound"

My Code

#Assignment 4
#Trying to do a EZ-music-player by pressing the button on UI
#No button required to play the music!
#It should be pretty straight-forward, just click the track you want to play
#Then it will play. Re-click the track will start over the song.
#If you want to add/remove some flavor for this song, just click the button.
#It have 9 music to load, so please be patient while loading
#Credits for the song goes to Daniel Sadowski, for creating these wonderful songs for Dota2 music pack!
add_library('sound')
#some Bools for making sure the Now-Playing status
m1L1B = False
m1L2B = False
m1L3B = False
m2L1B = False
m2L2B = False
m2L3B = False
m3L1B = False
m3L2B = False
m3L3B = False
xReso = 640
yReso = 480
sampleRate = xReso
#When mouse Clicked, pass the value to function
mouseClickPasser = False
def buttonCreation(posX, posY, sizeX, sizeY, setColor):
    global mouseClickPasser
    #Interpert Hex first
    
    
    if (mouseX > posX) and (mouseX < (posX + sizeX)) and (mouseY > posY) and (mouseY < (sizeY + posY)):
        fill(200,200,250)
        rect(posX, posY, sizeX, sizeY)
        if mouseClickPasser:
            mouseClickPasser = False
            return True
    else:
        fill(setColor)
        rect(posX, posY, sizeX, sizeY)
    return False
def mouseClicked():
    global mouseClickPasser
    mouseClickPasser = True
def setup():
    global m1L1, m1L2, m1L3, m2L1, m2L2, m2L3, m3L1, m3L2, m3L3
    global m1L1B, m1L2B, m1L3B, m2L1B, m2L2B, m2L3B, m3L1B, m3L2B, m3L3B
    global sampleRate, wf1, wf2, wf3
    global xReso, yReso
    
    size(xReso, yReso)
    background(0)
    fill(255)
    textSize(50)
    text( "Loading", 250, 200)
    #fill(255)
    #textSize(30)
    text( "EST: 10-20s ", 150, 280)
    
    frameRate(30)
    
    
    m2L1 = SoundFile(this, "lane1_layer1.mp3")
    m2L2 = SoundFile(this, "lane1_layer2.mp3")
    m2L3 = SoundFile(this, "lane1_layer3.mp3")
    m1L1 = SoundFile(this, "lane2_layer1.mp3")
    m1L2 = SoundFile(this, "lane2_layer2.mp3")
    m1L3 = SoundFile(this, "lane2_layer3.mp3")
    m3L1 = SoundFile(this, "lane3_layer1.mp3")
    m3L2 = SoundFile(this, "lane3_layer2.mp3")
    m3L3 = SoundFile(this, "lane3_layer3.mp3")
    
    wf1 = Waveform(this, sampleRate)
    wf2 = Waveform(this, sampleRate)
    wf3 = Waveform(this, sampleRate)
    
    wf1.input(m1L1)
    wf2.input(m2L1)
    wf3.input(m3L1)
    
def draw():
    global m1L1, m1L2, m1L3, m2L1, m22, m2L3, m3L1, m3L2, m3L3
    
    background(0)
    playBackground()
    
    playSound()
    playAddon()
def playBackground():
    global m1L1, m1L2, m1L3, m2L1, m2L2, m2L3, m3L1, m3L2, m3L3
    global m1L1B, m1L2B, m1L3B, m2L1B, m2L2B, m2L3B, m3L1B, m3L2B, m3L3B
    global sampleRate, wf1, wf2, wf3
    
    if m1L1B:
        drawSample(wf1, "#3c6ab5")
    elif m2L1B:
        drawSample(wf2, "#f05d30")
    elif m3L1B:
        drawSample(wf3, "#8e9c67")
    else:
        line(0, height/2, width, height/2)
        
    fill(96, 131, 184, 200)
    rect(12, 11, 169, 457)
    rect(225, 11, 402, 457)
    fill(255)
    textSize(60)
    text("Flavor Adder", 259, 154)
    textSize(30)
    text("Tracks", 47, 60)
        
def drawSample(waveform, colorHex):
    global sampleRate
    
    
    waveform.analyze()
    #print("waveform analyzed")
    fill(colorHex)
    noStroke()
    #print(str(waveform.data[100]))
    for i in range(sampleRate):
        rect(i, height/2 + waveform.data[i] * height /2 , 1, height/2 - waveform.data[i] * height / 2)
def stopAll():
    global m1L1, m1L2, m1L3, m2L1, m2L2, m2L3, m3L1, m3L2, m3L3
    global m1L1B, m1L2B, m1L3B, m2L1B, m2L2B, m2L3B, m3L1B, m3L2B, m3L3B
    if m1L1B:
        m1L1.stop()
        m1L2.stop()
        m1L3.stop()
        m1L1B = False
        m1L2B = False
        m1L3B = False
        
        #print("first should stopped now")
        
    elif m2L1B:
        m2L1.stop()
        m2L2.stop()
        m2L3.stop()
        m2L1B = False
        m2L2B = False
        m2L3B = False
    elif m3L1B:
        m3L1.stop()
        m3L2.stop()
        m3L3.stop()
        m3L1B = False
        m3L2B = False
        m3L3B = False
        
def playSound():
    global m1L1, m1L2, m1L3, m2L1, m2L2, m2L3, m3L1, m3L2, m3L3
    global m1L1B, m1L2B, m1L3B, m2L1B, m2L2B, m2L3B, m3L1B, m3L2B, m3L3B    
    
    if buttonCreation(30, 81, 135, 26, "#85EBE5"):
         
        stopAll()
        m1L1.play()
        m1L2.play()
        m1L3.play()
        
        m1L2.amp(0.001)
        m1L3.amp(0.001)
        
        m1L1B = True
        
    if buttonCreation(30, 122, 135, 26, "#85EBE5"):
        stopAll()
        m2L1.play()
        m2L2.play()
        m2L3.play()
        
        m2L2.amp(0.001)
        m2L3.amp(0.001)
        
        m2L1B = True
    
    if buttonCreation(30, 163, 135, 26, "#85EBE5"):
        stopAll()
        m3L1.play()
        m3L2.play()
        m3L3.play()
        
        m3L2.amp(0.001)
        m3L3.amp(0.001)
        
        m3L1B = True    
        
        
    fill(0)
    textSize(15)
    text("Cool Music", 59, 100)
    text("Hot Music", 63, 141)
    text("Human Music", 49, 182)
    
    
def playAddon():
    global m1L1, m1L2, m1L3, m2L1, m2L2, m2L3, m3L1, m3L2, m3L3
    global m1L1B, m1L2B, m1L3B, m2L1B, m2L2B, m2L3B, m3L1B, m3L2B, m3L3B    
    
    if m1L1B:
        if buttonCreation(271, 217, 127, 147, "#00B6F0"):
            if m1L2B:
                m1L2.amp(0.001)
                m1L2B = False
            else:
                m1L2.amp(1)
                m1L2B = True
        fill(255)
        textSize(30)
        if m1L2B:
            text("Remove", 283, 281)
        else:
            text("Add", 303,281)
        text("Delicate", 281, 317)
        
        if buttonCreation(442, 217, 135, 147, "#00B6F0"):
            if m1L3B:
                m1L3.amp(0.001)
                m1L3B = False
            else:
                m1L3.amp(1)
                m1L3B = True
        fill(255)
        textSize(30)
        if m1L3B:
            text("Remove", 447, 281)
        else:
            text("Add", 478,281)
        text("Beats", 465, 317)
    
    #Second Song
    if m2L1B:
        if buttonCreation(271, 217, 127, 147, "#00B6F0"):
            if m2L2B:
                m2L2.amp(0.001)
                m2L2B = False
            else:
                m2L2.amp(1)
                m2L2B = True
        fill(255)
        textSize(30)
        if m2L2B:
            text("Remove", 283, 281)
        else:
            text("Add", 303,281)
        text("Delicate", 281, 317)
        
        if buttonCreation(442, 217, 135, 147, "#00B6F0"):
            if m2L3B:
                m2L3.amp(0.001)
                m2L3B = False
            else:
                m2L3.amp(1)
                m2L3B = True
        fill(255)
        textSize(30)
        if m2L3B:
            text("Remove", 447, 281)
        else:
            text("Add", 478,281)
        text("Beats", 465, 317)
    #Third Song
    if m3L1B:
        if buttonCreation(271, 217, 127, 147, "#00B6F0"):
            if m3L2B:
                m3L2.amp(0.001)
                m3L2B = False
            else:
                m3L2.amp(1)
                m3L2B = True
        fill(255)
        textSize(30)
        if m3L2B:
            text("Remove", 283, 281)
        else:
            text("Add", 303,281)
        text("Delicate", 281, 317)
        
        if buttonCreation(442, 217, 135, 147, "#00B6F0"):
            if m3L3B:
                m3L3.amp(0.001)
                m3L3B = False
            else:
                m3L3.amp(1)
                m3L3B = True
        fill(255)
        textSize(30)
        if m3L3B:
            text("Remove", 447, 281)
        else:
            text("Add", 478,281)
        text("Beats", 465, 317)


Screenshot


Simple Painter App Gameplay

Download

Download
Assignment4_Sound.zip 19 MB

Install instructions

Must use processing 3 to run the code within the zip files.

Leave a comment

Log in with itch.io to leave a comment.