Refactor gen_volume into the GitMIDI class
This commit is contained in:
parent
6de165cb95
commit
a4a8aaea73
17
git-sound.py
17
git-sound.py
@ -46,13 +46,6 @@ programs = {
|
|||||||
program = programs['sitar-tablah']
|
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):
|
def sha_to_note(sha):
|
||||||
note_num = reduce(lambda res, digit: res + int(digit, 16),
|
note_num = reduce(lambda res, digit: res + int(digit, 16),
|
||||||
list(str(sha)), 0) % notecount
|
list(str(sha)), 0) % notecount
|
||||||
@ -117,6 +110,12 @@ class GitMIDI(MIDIFile):
|
|||||||
self.__setup_midi()
|
self.__setup_midi()
|
||||||
self.__setup_repo()
|
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):
|
def gen_beat(self, commit):
|
||||||
stat = commit.stats
|
stat = commit.stats
|
||||||
note = sha_to_note(commit.hexsha)
|
note = sha_to_note(commit.hexsha)
|
||||||
@ -127,7 +126,7 @@ class GitMIDI(MIDIFile):
|
|||||||
file_notes.append({
|
file_notes.append({
|
||||||
'note': sha_to_note(get_file_sha(commit, file_name)) +
|
'note': sha_to_note(get_file_sha(commit, file_name)) +
|
||||||
program['file']['octave'] * 12,
|
program['file']['octave'] * 12,
|
||||||
'volume': gen_volume(file_stat['deletions'],
|
'volume': self.gen_volume(file_stat['deletions'],
|
||||||
file_stat['insertions'],
|
file_stat['insertions'],
|
||||||
deviation=10),
|
deviation=10),
|
||||||
})
|
})
|
||||||
@ -135,7 +134,7 @@ class GitMIDI(MIDIFile):
|
|||||||
return {
|
return {
|
||||||
'commit_note': sha_to_note(commit.hexsha) +
|
'commit_note': sha_to_note(commit.hexsha) +
|
||||||
program['commit']['octave'] * 12,
|
program['commit']['octave'] * 12,
|
||||||
'commit_volume': gen_volume(stat.total['deletions'],
|
'commit_volume': self.gen_volume(stat.total['deletions'],
|
||||||
stat.total['insertions'],
|
stat.total['insertions'],
|
||||||
deviation=20),
|
deviation=20),
|
||||||
'file_notes': file_notes,
|
'file_notes': file_notes,
|
||||||
|
Loading…
Reference in New Issue
Block a user