From a4a8aaea733adf861fce915db6b852528cc54c60 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 24 May 2016 13:22:13 +0200 Subject: [PATCH] Refactor gen_volume into the GitMIDI class --- git-sound.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/git-sound.py b/git-sound.py index cd665bf..c6500ef 100644 --- a/git-sound.py +++ b/git-sound.py @@ -46,13 +46,6 @@ programs = { program = programs['sitar-tablah'] -def gen_volume(deletions, insertions, deviation=10): - return max( - deviation, - min(255 - deviation, - 127 - deletions + insertions)) - - def sha_to_note(sha): note_num = reduce(lambda res, digit: res + int(digit, 16), list(str(sha)), 0) % notecount @@ -117,6 +110,12 @@ class GitMIDI(MIDIFile): self.__setup_midi() self.__setup_repo() + def gen_volume(self, deletions, insertions, deviation=10): + return max( + deviation, + min(255 - deviation, + 127 - deletions + insertions)) + def gen_beat(self, commit): stat = commit.stats note = sha_to_note(commit.hexsha) @@ -127,17 +126,17 @@ class GitMIDI(MIDIFile): file_notes.append({ 'note': sha_to_note(get_file_sha(commit, file_name)) + program['file']['octave'] * 12, - 'volume': gen_volume(file_stat['deletions'], - file_stat['insertions'], - deviation=10), + 'volume': self.gen_volume(file_stat['deletions'], + file_stat['insertions'], + deviation=10), }) return { 'commit_note': sha_to_note(commit.hexsha) + program['commit']['octave'] * 12, - 'commit_volume': gen_volume(stat.total['deletions'], - stat.total['insertions'], - deviation=20), + 'commit_volume': self.gen_volume(stat.total['deletions'], + stat.total['insertions'], + deviation=20), 'file_notes': file_notes, }