Exemple #1
0
 def appStarted(app, beats, path):
     beats = beats.Beats(path).getBeats()
     app.beats = set(beats)
     print(app.beats)
     app.count = 0
     app.timerDelay = 1
     app.drawCircle = False
Exemple #2
0
 def appStarted(self):
     self.beatObj = bP.Beats(song)
     self.beats = self.beatObj.getBeats()
     self.beatVals = set(self.beats)
     self.values = set()
     for val in self.beatVals:
         self.values.add(round(val))
     self.count = 0
     self.frames = self.beatObj.totalFrames
     self.color = 'red'
Exemple #3
0
    def appStarted(self):

        # TIME
        self.time = 0
        self.seconds = 0
        self.timerDelay = 100 # milliseconds

        # GENERAL THINGS
        self.gameOver = False
        self.msg = None

        # SONG LENGTH
        self.songLen = lenSong.AudioObject(song).lengthInSecs

        # PITCH
        self.pitchPath = pmp.PitchPath(song)
        self.path = self.pitchPath.getPitchPath() # Dictionary of frames to pitch
        self.frames = self.pitchPath.totalFrames # Total frames in pitchPath
        self.range = self.pitchPath.getPitchRange() # Range of pitches
        self.minPitch = self.pitchPath.getMinPitch() # Lowest pitch

        self.pitchPath = [] # Path of (x,y) based on (frame, pitch)
        self.xVals = []
        self.yVals = []
        for time in self.path:
            pitch = self.path[time]
            yVal = self.height//3 + ((pitch-self.minPitch)/self.range)*(self.height//3) # Scale y value by pitch, relative to range of pitches
            xVal = time
            self.xVals.append(xVal)
            self.yVals.append(yVal)
            self.pitchPath.append((xVal, yVal))

        # Manually add last values of song
        # Therefore function never goes out of range while song is still going
        lastVal = self.pitchPath[-1][1]
        self.xVals.append(self.songLen)
        self.yVals.append(lastVal)
        self.pitchPath.append((self.songLen, lastVal))

        x = self.xVals
        y = self.yVals
        self.f = interp1d(x, y, kind='cubic')

        # BEATS
        self.beatObj = bP.Beats(song)
        self.beats = self.beatObj.getBeats()
        self.beatVals = self.beatObj.roundToFirstDecimal()

        # BPM
        self.bpm = self.beatObj.convertBeatsToBPM()

        # PLAYER
        self.player = player.Player(self.width//4, self.height//2)
        self.attack = False
        self.injured = False
        # PLAYER SPRITE
        path = r'C:\Users\Amy\15-112\termProject\TP2_Deliverable\spritesheet_png.png'
        spritestrip = self.loadImage(path)
        self.sprites = []
        for i in range(4):
            # height: 0 - 200
            # width: i*200 + (i+1)*200
            bigSprite = spritestrip.crop((i*200, 0, (i+1)*200, 200))
            sprite = self.scaleImage(bigSprite, 1/2)
            sDims = sprite.size
            self.sprites.append(sprite)
        self.spriteCounter = 0
        self.r = (sDims[0]**2 + sDims[1]**2)**0.5 // 2

        # MOVEMENT
        self.scrollX = 0 # Scroll x value
        self.dx = self.bpm / 30 # 'Speed' based on bpm (avg 60)

        # PROJECTILE
        self.projectiles = []
        self.dpx = self.dx*6
        self.timeToReachPlayer = (self.width - self.player.x) / (self.dpx/0.1) # In seconds
        self.timeToReachPlayer = PitchPathmaker.roundToOneDecimal(self.timeToReachPlayer) # Round
        self.projectileYTime = self.timeToReachPlayer * 10 # Convert to 0.1 seconds (100 ms)

        self.apy = 2 # "Gravity"; i.e. acceleration of projectile in y-direction (APY)

        # BACKGROUND - for future implementation
        self.length = self.dx * (self.songLen/0.1)
Exemple #4
0
import os
import beatsParser as beats
import cmu_112_graphics as graphics

mydir = r'C:\Users\Amy\15-112\termProject\aubio_demo\sampleAudio'
myfile = 'file_example_WAV_1MG.wav'

fileName = mydir + os.sep + myfile

beatObj = beats.Beats(fileName)

beats = beatObj.getBeats()

class BeatMaker(graphics.App):
    def appStarted(app, beats, path):
        beats = beats.Beats(path).getBeats()
        app.beats = set(beats)
        print(app.beats)
        app.count = 0
        app.timerDelay = 1
        app.drawCircle = False

    def timerFired(app, beats):
        if app.count in app.beats:
            app.drawCircle = True
            print(f'Drew circle for {app.count}')
        else:
            app.drawCircle = False
    
    def redrawAll(app, canvas):
        r = 20
    def appStarted(self):
        self.time = 0
        self.seconds = 0
        self.timerDelay = 100 # milliseconds

        self.gameOver = False

        # SONG LENGTH

        self.songLen = lenSong.AudioObject(song).lengthInSecs

        # PITCH

        self.pitchPath = pmp.PitchPath(song)
        self.path = self.pitchPath.getPitchPath() # Dictionary of frames to pitch
        self.frames = self.pitchPath.totalFrames # Total frames in pitchPath
        self.range = self.pitchPath.getPitchRange() # Range of pitches
        self.minPitch = self.pitchPath.getMinPitch() # Lowest pitch

        self.pitchPath = [] # Path of (x,y) based on (frame, pitch)
        self.xVals = []
        self.yVals = []
        for time in self.path:
            pitch = self.path[time]
            yVal = self.height//3 + ((pitch-self.minPitch)/self.range)*(self.height//3)
            xVal = time
            self.xVals.append(xVal)
            self.yVals.append(yVal)
            self.pitchPath.append((xVal, yVal))

        # Manually add last values of song, so that function never goes out of range
        lastVal = self.pitchPath[-1][1]
        self.xVals.append(self.songLen)
        self.yVals.append(lastVal)
        self.pitchPath.append((self.songLen, lastVal))

        x = self.xVals
        y = self.yVals
        self.f = interp1d(x, y, kind='cubic')
#        plt.plot(x, y, 'o', x, self.f(x), '-')
#        plt.show()

        # BEATS

        self.beatObj = bP.Beats(song)
        self.beats = self.beatObj.getBeats()
        self.beatVals = self.beatObj.roundToFirstDecimal()

        self.color = 'red'

        # BPM
        self.bpm = self.beatObj.convertBeatsToBPM()

        # PLAYER
        self.player = player.Player(self.width//4, self.height//2)
        self.attack = False
        self.injured = False

        # MOVEMENT
        self.scrollX = 0 # Scroll x value
        self.dx = self.bpm / 30 # 'Speed' based on bpm (avg 60)

        # PROJECTILE
        self.dpx = self.dx*6
        self.timeToReachPlayer = (self.width - self.player.x) / (self.dpx/0.1) # In seconds
        self.timeToReachPlayer = PitchPathmaker.roundToOneDecimal(self.timeToReachPlayer) # Round
        self.projectileYTime = self.timeToReachPlayer * 10 # Convert to 0.1 seconds (100 ms)
        self.projectile = False
        self.startProj = -1
        self.pr = 20
        self.px = self.width
        self.py = self.height//2
        self.finalY = None # Final y position, to match with player on the beat
        self.dpy = 0 # Initial y velocity
        self.apy = 2 # "Gravity"; i.e. acceleration of projectile in y-direction (APY)

        # BACKGROUND
        self.length = self.dx * (self.songLen/0.1)
Exemple #6
0
    def setAudioValues(self, song):
        self.song = song

        # SONG LENGTH
        self.songLen = lenSong.AudioObject(self.song).lengthInSecs

        # BEATS
        self.beatObj = bP.Beats(self.song)
        self.beats = self.beatObj.getBeats()
        self.beatVals = self.beatObj.roundToFirstDecimal()

        # BPM
        self.bpm = self.beatObj.convertBeatsToBPM()

        # MOVEMENT
        self.scrollX = 0  # Scroll x value
        self.dx = self.bpm / 10  # 'Speed' based on bpm (avg 60)

        # BACKGROUND
        self.length = self.dx * (self.songLen / 0.1)

        # PITCH
        self.pitchPath = pmp.PitchPath(self.song)
        self.path = self.pitchPath.getPitchPath(
        )  # Dictionary of frames to pitch
        self.frames = self.pitchPath.totalFrames  # Total frames in pitchPath
        self.range = self.pitchPath.getPitchRange()  # Range of pitches
        self.minPitch = self.pitchPath.getMinPitch()  # Lowest pitch

        self.pitchPath = [(0, self.height // 2)
                          ]  # Path of (x,y) based on (frame, pitch)
        self.curvePathVals = [(self.width // 4, self.height // 2)
                              ]  # Path of (x, y) based on (scrollX, height)
        self.xVals = []
        self.yVals = []
        for time in self.path:
            pitch = self.path[time]
            yVal = self.height // 4 + (
                (pitch - self.minPitch) / self.range) * (
                    self.height // 2
                )  # Scale y value by pitch, relative to range of pitches
            xVal = time
            xValForCurve = (self.dx * time * 10) + self.width // 4
            self.xVals.append(xVal)
            self.yVals.append(yVal)
            self.pitchPath.append((xVal, yVal))
            self.curvePathVals.append((xValForCurve, yVal))

        # Manually add last values of song
        # Therefore function never goes out of range while song is still going
        lastVal = self.pitchPath[-1][1]
        self.xVals.append(self.songLen)
        self.yVals.append(lastVal)
        self.pitchPath.append((self.songLen, lastVal))
        self.curvePathVals.append((self.length, lastVal))
        self.curvePath = tuple(self.curvePathVals)

        x = self.xVals
        y = self.yVals
        self.f = interp1d(x, y, kind='cubic')

        # ENEMY
        self.enemy = eC.Enemy(self.width - 100, self.height // 2)
        ex = self.enemy.x
        ey = self.enemy.y

        # PROJECTILE
        self.projectiles = []
        self.dpx = self.dx * 2
        self.timeToReachPlayer = (
            (self.width - self.enemyXSize) - self.player.x) / (self.dpx / 0.1
                                                               )  # In seconds
        self.timeToReachPlayer = PitchPathmaker.roundToOneDecimal(
            self.timeToReachPlayer)  # Round
        self.projectileYTime = self.timeToReachPlayer * 10  # Convert to 0.1 seconds (100 ms)

        self.apy = 1  # "Gravity"; i.e. acceleration of projectile in y-direction (APY)

        winsound.PlaySound(self.song, winsound.SND_ASYNC | winsound.SND_ALIAS)