From d85052fafd94ea49b448c2b1558c4e43b8a0b023 Mon Sep 17 00:00:00 2001 From: Gergely Polonkai Date: Tue, 24 May 2016 13:32:34 +0200 Subject: [PATCH] Make program a parameter to the GitMIDI class --- git-sound.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/git-sound.py b/git-sound.py index 847a977..def500b 100644 --- a/git-sound.py +++ b/git-sound.py @@ -41,7 +41,6 @@ programs = { }, }, } -program = programs['sitar-tablah'] def get_file_sha(commit, file_name): @@ -63,6 +62,9 @@ def get_file_sha(commit, file_name): class GitMIDI(MIDIFile): + LOG_CHANNEL = 0 + FILE_CHANNEL = 1 + def __setup_midi(self, track_title=None): if self.__verbose: print("Preparing MIDI track…") @@ -74,6 +76,11 @@ class GitMIDI(MIDIFile): # TODO: Make this configurable self.addTempo(0, 0, 120) + self.addProgramChange(0, self.LOG_CHANNEL, + 0, self.__program['commit']['program']) + self.addProgramChange(0, self.FILE_CHANNEL, + 0, self.__program['file']['program']) + def __setup_repo(self): if self.__verbose: print("Analyzing repository…") @@ -85,7 +92,8 @@ class GitMIDI(MIDIFile): repository='.', branch='master', verbose=False, - scale=None): + scale=None, + program=None): MIDIFile.__init__(self, 1) @@ -99,6 +107,7 @@ class GitMIDI(MIDIFile): self.git_log = [] self.mem_file = StringIO() self.__scale = scale + self.__program = program self.__setup_midi() self.__setup_repo() @@ -123,7 +132,7 @@ class GitMIDI(MIDIFile): for file_name, file_stat in stat.files.items(): file_notes.append({ 'note': self.sha_to_note(get_file_sha(commit, file_name)) + - program['file']['octave'] * 12, + self.__program['file']['octave'] * 12, 'volume': self.gen_volume(file_stat['deletions'], file_stat['insertions'], deviation=10), @@ -131,7 +140,7 @@ class GitMIDI(MIDIFile): return { 'commit_note': self.sha_to_note(commit.hexsha) + - program['commit']['octave'] * 12, + self.__program['commit']['octave'] * 12, 'commit_volume': self.gen_volume(stat.total['deletions'], stat.total['insertions'], deviation=20), @@ -227,7 +236,8 @@ try: repo_midi = GitMIDI(repository=args.repository, branch=args.branch, verbose=args.verbose, - scale=scales['a-harmonic-minor']) + scale=scales['a-harmonic-minor'], + program=programs['sitar-tablah']) except InvalidGitRepositoryError: print("{} is not a valid Git repository".format( @@ -254,11 +264,6 @@ decor_channel = 1 # Duration of one note duration = 0.3 -repo_midi.addProgramChange(track, log_channel, - 0, program['commit']['program']) -repo_midi.addProgramChange(track, decor_channel, - 0, program['file']['program']) - # WRITE THE SEQUENCE for section in log: section_len = len(section['file_notes']) * duration