Skip to content

Commit

Permalink
new exercise: left hand random 2-3-4 fingers
Browse files Browse the repository at this point in the history
Fixes #16
  • Loading branch information
keremkoseoglu committed Jun 10, 2020
1 parent 291718f commit 6dae144
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[MESSAGES CONTROL]
disable=W0703, R0902, R0903, R1716, R0801, C0200, R0916
disable=W0703, R0902, R0903, R1716, R0801, C0200, R0916, R0914
Empty file added body/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions body/hand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
""" Module for human hand """
from typing import List
from copy import copy
from random import randint

class Finger:
""" Finger class """
def __init__(self, number: int, name: str):
self.number = number
self.name = name

class Hand:
""" Hand class """
def __init__(self):
self.fingers = [
Finger(1, "Index"),
Finger(2, "Middle"),
Finger(3, "Ring"),
Finger(4, "Pinky"),
Finger(5, "Thumb")
]

def get_random_fret_fingers(self, quantity: int = 0) -> List[Finger]:
""" Returns a random list of fretting fingers """
output = []
candidates = copy(self.fingers)
candidates.pop(4)

if quantity > 0:
output_quantity = quantity
else:
output_quantity = randint(0, len(candidates)-1)

while len(output) < output_quantity and len(candidates) > 0:
random_index = randint(0, len(candidates)-1)
random_finger = candidates.pop(random_index)
output.append(random_finger)

return output
9 changes: 5 additions & 4 deletions factory/some_practices.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@ class SomePractices(abstract_factory.AbstractFactory):
def __init__(self):
super().__init__()
self._select_guitar = True
self.guitar = Guitar.UNDEFINED

def get_workout(self, guitar: Guitar = Guitar.UNDEFINED) -> workout.WorkOut:
""" Returns a new workout containing all practices """
if self._select_guitar:
random_guitar = get_random_guitar()
self.guitar = get_random_guitar()
else:
random_guitar = guitar
self.guitar = guitar

output = all_practices.AllPractices().get_workout(random_guitar)
output = all_practices.AllPractices().get_workout(self.guitar)
remove_percent = random.randint(self._LOW_PERCENT, self._HIGH_PERCENT)
output.remove_random_exercies(remove_percent)

if self._select_guitar:
output.add_guitar(random_guitar)
output.add_guitar(self.guitar)
return output

def set_select_guitar(self, select: bool):
Expand Down
6 changes: 5 additions & 1 deletion gui/face.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from kivy.uix.label import Label
from factory import some_practices
from gui.button_event import ButtonEvent
from model.guitar import Guitar


_APP_TITLE = "Guitar Training Remote"
Expand Down Expand Up @@ -101,6 +102,7 @@ def __init__(self, **kwargs):
self._workout = None
self._exercise_step_tick_count = 0
self._guitar_selected = False
self._guitar = Guitar.UNDEFINED
self._restart()

def _handle_button_click(self, button: int):
Expand Down Expand Up @@ -156,16 +158,18 @@ def _restart(self):
practice_obj = some_practices.SomePractices()
if self._guitar_selected:
practice_obj.set_select_guitar(False)
self._workout = practice_obj.get_workout(self._guitar)
else:
practice_obj.set_select_guitar(True)
self._guitar_selected = True
self._workout = practice_obj.get_workout()

self._workout = practice_obj.get_workout()
self._exercise_step_tick_count = -1
self._paint_exercise()
self._paint_exercise_step()
self._buttons.set_next_enabled(True)
self._refresh_status_text()
self._guitar = practice_obj.guitar


class GtrApp(App):
Expand Down
61 changes: 61 additions & 0 deletions practice/lazy_fingers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
""" Lazy fingers module
This module contains exercises for left hand fingers 2, 3, 4
"""
from random import randint
from model import exercise, exercise_step
from model.guitar import Guitar
from practice.abstract_practice import AbstractPractice
from body.hand import Hand


class LazyFingers(AbstractPractice):
""" Lazy fingers exercise class """

_TITLE = "Lazy fingers"
_SUBTITLE = "Work your lazy fingers"
_BASS_STRINGS = 4
_GUITAR_STRINGS = 6

def get_exercise(self, quantity: int, guitar: Guitar) -> exercise.Exercise:
""" Returns lazy fingers exercises """
random_steps = []

if guitar == Guitar.KEYS:
return None
if guitar == Guitar.BASS:
string_count = LazyFingers._BASS_STRINGS
else:
string_count = LazyFingers._GUITAR_STRINGS

for quantity_pos in range(quantity): # pylint: disable=W0612
random_finger_count = randint(2, 4)
random_fingers = Hand().get_random_fret_fingers(random_finger_count)
strings = []
fingers = []

while len(random_fingers) > 0:
random_finger_index = randint(0, len(random_fingers)-1)
random_finger = random_fingers.pop(random_finger_index)
fingers.append(random_finger)
random_string = randint(1, string_count)
strings.append(random_string)

sorted(strings, key=lambda string: string)
sorted(fingers, key=lambda finger: finger.number)

pattern = ""
for pattern_index in range(len(strings)):
if pattern == "":
pattern += " "
pattern += "S" + str(strings[pattern_index])
pattern += " " + fingers[pattern_index].name

random_step = exercise_step.ExerciseStep(
"Follow the pattern",
pattern
)

random_steps.append(random_step)

output = exercise.Exercise(self._TITLE, self._SUBTITLE, random_steps)
return output
1 change: 0 additions & 1 deletion technique/right_hand.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ def __init__(self):
"4 finger gallop",
"3 finger scale",
"Chr. seesaw",
"String crossing",
"Palm mute triplet",
"Scott's speed test"
]
Expand Down

0 comments on commit 6dae144

Please sign in to comment.