Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 31 additions & 18 deletions RankPanda/Commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,56 +12,69 @@ def __init__(self, length, beginLocation):
self._name = 'Command'


# Given the beginning location, calculates the location that the
# rank should be in after count counts. Uses information such as
# self._delta and the command type, but does NOT use
# self.endLocation.


# Be sure to overwrite this in each Command!
def CalcLocation(self, count, beginLocation):
""" Given the beginning location, calculates the location that the
rank should be in after count counts. Uses information such as
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: please line wrap to match the same column the initial """ starts on, and end with """ on its own line to match style elsewhere, such as here: https://github.com/astory/RankPanda/blob/master/RankPanda/RankLocation.py

(Please also do this for the rest of the docstrings)

thanks so much for moving these to docstrings though!

self._delta and the command type, but does NOT use
self.endLocation.
"""
return beginLocation

# Splits the command in two, at the specified count. Changes this command
# to be the appropriate length, and returns this command as well as the
# new one.


# Be sure to overwrite this in each Command!
def Split(self, count, beginLocation):
""" Splits the command in two, at the specified count. Changes this command
to be the appropriate length, and returns this command as well as the
new one.
"""
pass

# Returns the current value of the self._name field.

def GetName(self):
""" Returns the current value of the self._name field."""
return self._name

# Sets the value of the self._name field.

def SetName(self, name):
""" Sets the value of the self._name field."""
self._name = name

# Returns the number of counts this command spans. If you want to change
# this value, make a new command instead.

def GetLength(self):
"""Returns the number of counts this command spans. If you want to change
this value, make a new command instead.
"""
return round(self._length)

# Simple getter, in case the beginning location isn't readily available.

def GetEndLocation(self):
"""Simple getter, in case the beginning location isn't readily available."""
return self._endLocation

def SnapEndLocation(self, newBeginLocation):
self._endLocation = self.CalcLocation(self.GetLength(), newBeginLocation)

# From the ending location, calculate the beginning location. Will require
# basically the same implementation as CalcLocation(), but in reverse.
# count should be the location in the whole command you want it to be
# returned. So, pass in 0 to run the whole command.


# Be sure to overwrite this in each Command!
def CalcBeginLocation(self, count, endLocation):
"""From the ending location, calculate the beginning location.
Will require basically the same implementation as CalcLocation(),
but in reverse. count should be the location in the whole command
you want it to be returned. So, pass in 0 to run the whole command.
"""
return None

# Checks following to see if it's a command of the same name. If so,
# return the merged commands.


def MergeWithFollowing(self, following):
""" Checks following to see if it's a command of the same name. If so,
return the merged commands.
"""
if ((following._name == self._name) and (isinstance(following, self))):
self._length = self._length + following._length
self._endLocation = following._endLocation
Expand Down
57 changes: 17 additions & 40 deletions RankPanda/CoreWrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class CoreWrapper(object):
def __init__(self, title, numberMeasures, CountsPerMeasureList, StepsPerCountList):
if (numberMeasures < 1):
raise NameError("Number of measures can't be less than 1!")
if (len(CountsPerMeasureList) == 0):
raise NameError("You must input the initial number of counts per measure!")
if (CountsPerMeasureList[0][0] != 1):
if (len(CountsPerMeasureList) == 0 or CountsPerMeasureList[0][0] != 1):
raise NameError("You must input the initial number of counts per measure!")
self._song = Song.Song(title, numberMeasures, CountsPerMeasureList[0][1])
i = 1
Expand Down Expand Up @@ -54,16 +52,13 @@ def GetSong(self):
# [(0, 'Move 0'), (1, 'Move 1'), ...]
def GetMoves(self):
listOfMoves = self._song.GetMoveList()
i = 0
moveInfo = []
while (i < len(listOfMoves)):
curmove = listOfMoves[i]
moveInfo.append((curmove.GetNumber(), curmove.GetName()))
i = i + 1
return moveInfo
return [(curmove.GetNumber(), curmove.GetName()) for curmove in listOfMoves]




# Returns (current move number, current move name, current length of move in counts)
# Returns None is there is no current move
# Returns None if there is no current move
def GetCurrentMove(self):
if (self._song.currentMove is None):
return None
Expand All @@ -76,31 +71,16 @@ def GetCurrentMove(self):
# ?
# List of all ranks in current move
# [(id0, name0, location0), (id1, name1, location1)]
def GetRanks(self):
if (self._song.currentMove is None):
return None
allRanks = self._song.currentMove.GetAllRanks()
i = 0
allRankInfo = []
while (i < len(allRanks)):
allRankInfo.append((allRanks[i].GetID(), allRanks[i].GetName(), allRanks[i].GetEndLocation(), allRanks[i].GetLabelLocation()))
i = i + 1
return allRankInfo


# Same as above but now you input the move number.
def GetRanksGivenMove(self, moveNumber):
def GetRanks(self, moveNumber = None):
if (self._song.currentMove is None):
return None
allRanks = self._song.GetMoveList()[moveNumber].GetAllRanks()
i = 0
allRankInfo = []
while (i < len(allRanks)):
allRankInfo.append((allRanks[i].GetID(), allRanks[i].GetName(), allRanks[i].GetEndLocation(), allRanks[i].GetLabelLocation()))
i = i + 1
return allRankInfo


if (moveNumber is None):
allRanks = self._song.currentMove.GetAllRanks()
else:
allRanks = self._song.GetMoveList()[moveNumber].GetAllRanks()
return [(r.GetID(), r.GetName(), r.GetEndLocation(),\
r.GetLabelLocation()) for r in allRanks]

def IsRankHeld(self, ID):
if (self._song.currentMove is None):
return None
Expand All @@ -113,12 +93,8 @@ def GetSelectedRanks(self):
if (self._song.currentMove is None):
return None
allSelectedRanks = self._song.currentMove.GetSelectedRanks()
i = 0
allSelectedRankInfo = []
while (i < len(allSelectedRanks)):
allSelectedRankInfo.append((allSelectedRanks[i].GetID(), allSelectedRanks[i].GetName(), allSelectedRanks[i].GetEndLocation(), allSelectedRanks[i].GetLabelLocation()))
i = i + 1
return allSelectedRankInfo
return [(r.GetID(), r.GetName(), r.GetEndLocation(),\
r.GetLabelLocation()) for r in allSelectedRanks]

def GetAdditionalRanks(self):
curList = []
Expand Down Expand Up @@ -775,6 +751,7 @@ def RankDeleteSpline(self, rankID, number):
return None
self._song.currentMove.LookUpID(rankID).DeleteSplinePoint(number)

#(Brady) TODO: prevent changing name if not on the very first move.
# Pass in the ID of the rank to name, and its new name.
def NameRank(self, name):
if (self._song.currentMove is None):
Expand Down
Loading