Make volume range configurable from the command line
This commit is contained in:
parent
1304806c11
commit
6b3f68a5bb
24
git-sound.py
24
git-sound.py
@ -116,8 +116,8 @@ class GitMIDI(MIDIFile):
|
|||||||
branch='master',
|
branch='master',
|
||||||
verbose=False,
|
verbose=False,
|
||||||
scale=None,
|
scale=None,
|
||||||
program=None):
|
program=None,
|
||||||
|
volume_range=107):
|
||||||
MIDIFile.__init__(self, 1)
|
MIDIFile.__init__(self, 1)
|
||||||
|
|
||||||
self.__verbose = verbose
|
self.__verbose = verbose
|
||||||
@ -131,6 +131,7 @@ class GitMIDI(MIDIFile):
|
|||||||
self.mem_file = StringIO()
|
self.mem_file = StringIO()
|
||||||
self.__scale = scale
|
self.__scale = scale
|
||||||
self.__program = program
|
self.__program = program
|
||||||
|
self.__volume_deviation = min(abs(63 - volume_range), 63)
|
||||||
|
|
||||||
self.__need_commits = self.__program['commit']['program'] is not None
|
self.__need_commits = self.__program['commit']['program'] is not None
|
||||||
self.__need_files = self.__program['file']['program'] is not None
|
self.__need_files = self.__program['file']['program'] is not None
|
||||||
@ -138,7 +139,7 @@ class GitMIDI(MIDIFile):
|
|||||||
self.__setup_midi()
|
self.__setup_midi()
|
||||||
self.__setup_repo()
|
self.__setup_repo()
|
||||||
|
|
||||||
def gen_volume(self, deletions, insertions, deviation=10):
|
def gen_volume(self, deletions, insertions):
|
||||||
"""
|
"""
|
||||||
Generate a volume based on the number of modified lines
|
Generate a volume based on the number of modified lines
|
||||||
(insertions - deletions).
|
(insertions - deletions).
|
||||||
@ -148,8 +149,8 @@ class GitMIDI(MIDIFile):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return max(
|
return max(
|
||||||
deviation,
|
self.__volume_deviation,
|
||||||
min(127 - deviation,
|
min(127 - self.__volume_deviation,
|
||||||
63 - deletions + insertions))
|
63 - deletions + insertions))
|
||||||
|
|
||||||
def sha_to_note(self, sha):
|
def sha_to_note(self, sha):
|
||||||
@ -168,16 +169,14 @@ class GitMIDI(MIDIFile):
|
|||||||
'note': self.sha_to_note(get_file_sha(commit, file_name)) +
|
'note': self.sha_to_note(get_file_sha(commit, file_name)) +
|
||||||
self.__program['file']['octave'] * 12,
|
self.__program['file']['octave'] * 12,
|
||||||
'volume': self.gen_volume(file_stat['deletions'],
|
'volume': self.gen_volume(file_stat['deletions'],
|
||||||
file_stat['insertions'],
|
file_stat['insertions']),
|
||||||
deviation=10),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'commit_note': self.sha_to_note(commit.hexsha) +
|
'commit_note': self.sha_to_note(commit.hexsha) +
|
||||||
self.__program['commit']['octave'] * 12,
|
self.__program['commit']['octave'] * 12,
|
||||||
'commit_volume': self.gen_volume(stat.total['deletions'],
|
'commit_volume': self.gen_volume(stat.total['deletions'],
|
||||||
stat.total['insertions'],
|
stat.total['insertions']),
|
||||||
deviation=20),
|
|
||||||
'file_notes': file_notes,
|
'file_notes': file_notes,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,6 +303,10 @@ if __name__ == '__main__':
|
|||||||
type=str,
|
type=str,
|
||||||
default=None,
|
default=None,
|
||||||
help="Program setting to use in the generated track")
|
help="Program setting to use in the generated track")
|
||||||
|
parser.add_argument('--volume-range',
|
||||||
|
type=int,
|
||||||
|
default=100,
|
||||||
|
help="The volume range to use.")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
@ -347,7 +350,8 @@ try:
|
|||||||
branch=args.branch,
|
branch=args.branch,
|
||||||
verbose=args.verbose,
|
verbose=args.verbose,
|
||||||
scale=scales[args.scale],
|
scale=scales[args.scale],
|
||||||
program=programs[args.program])
|
program=programs[args.program],
|
||||||
|
volume_range=args.volume_range)
|
||||||
|
|
||||||
except InvalidGitRepositoryError:
|
except InvalidGitRepositoryError:
|
||||||
print("{} is not a valid Git repository".format(
|
print("{} is not a valid Git repository".format(
|
||||||
|
Loading…
Reference in New Issue
Block a user