Skip to content

Commit

Permalink
Alpha version. Beat type assigned to MIDI CC2
Browse files Browse the repository at this point in the history
  • Loading branch information
r-koubou committed Nov 20, 2018
1 parent fa00bd5 commit 873e4a1
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 20 deletions.
8 changes: 6 additions & 2 deletions NOTICE
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
This software depends following libraries to work.
- pretty_midi
- clipboard

pretty_midi
https://pypi.org/project/pretty_midi/

clipboard
https://pypi.org/project/clipboard/
17 changes: 11 additions & 6 deletions appinfo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# coding: utf-8
APPNAME = 'BS Midi Converter'
AUTHOR = 'R-Koubou'
VERSION = '0.0.1'
URL = 'https://github.com/r-koubou/BS-Midi-Converter'
DESCRIPTION = 'Advanced Midi Converter for Beat Saber'
EXECUTABLE = 'BSMConverter'

VERSION = '0.0.1'
AUTHOR = 'NAME'
MAIN_SCRIPT = 'main.py'
EXECUTABLE_NAME = 'executable'
DESCRIPTION = "Application's description"
URL = "https://example.com"
VERSION_0_0_1 = 0x000010
VERSION_NUMBER = VERSION_0_0_1

if __name__ == '__main__':
print( VERSION )
71 changes: 60 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# conding: utf-8
# coding: utf-8
import json
import sys

import pretty_midi
import clipboard

import appinfo

TEMPLATE_BODY = {
"_version": "1.5.0",
"_beatsPerMinute": 120,
Expand Down Expand Up @@ -57,9 +59,9 @@ def to_line_layer( note ):
# | * |
# * | |
vel = note.velocity
if( vel < 42 ):
if( vel <= 42 ):
return 0
elif( vel < 83 ):
elif( vel <= 83 ):
return 1
else:
return 2
Expand Down Expand Up @@ -101,26 +103,47 @@ def to_line_cut_direction( note ):
# invalid
return 0

# CC2 Value to "_type" value
def to_beat_type( cc2 ):
# CC2: Beat type
# 0-31: Red(0)
# 32-63: Blue(1)
# 64-96: Bomb(2)
cc2Value = cc2.value
if( cc2Value <= 31 ):
return 0
elif( cc2Value <= 63 ):
return 1
elif( cc2Value <= 96 ):
return 2
else:
# invalid
return 0

# main
def main():
midi = pretty_midi.PrettyMIDI( sys.argv[1] )
def main( argv ):
midi = pretty_midi.PrettyMIDI( argv[ 0 ] )
midi_tracks = midi.instruments
bpm = midi.estimate_tempo()
score = TEMPLATE_BODY.copy()
score[ "_beatsPerMinute" ] = bpm

for i, t in enumerate( midi_tracks ):
for t in midi_tracks:
ccList = t.control_changes
beat_type = 0
for cc in ccList:
beat_type = to_beat_type( cc )
break

for note in t.notes:
# note.start: Note On time (sec)
# note.pitch: Note No
# note.velocity: Velocity
n = TEMPLATE_NOTE.copy()

# MIDI track 1: Red
# MIDI track 2: Blue
n[ "_type" ] = i

# MIDI track 1(i==0): Red
# MIDI track 2(i==1): Blue
n[ "_type" ] = beat_type
n[ "_time" ] = (bpm/60)*note.start
n[ "_lineIndex" ] = to_line_index( note )
n[ "_lineLayer" ] = to_line_layer( note )
Expand All @@ -130,5 +153,31 @@ def main():

clipboard.copy( json.dumps( score, indent=4 ) )

def usage():
USAGE = """
{appname} by {author} ({url})
{description}
1: Run from python
** Call setup-venv.bat, setup-libs.bat once to execute **
python main.py <midifile>
2: Run from exe
{executable}.exe <midifile>
or
Drag & Drop a midi file to {executable}.exe""".format(
appname=appinfo.APPNAME,
author=appinfo.AUTHOR,
url=appinfo.URL,
description=appinfo.DESCRIPTION,
executable=appinfo.EXECUTABLE
)

print( USAGE )

if __name__ == "__main__":
main()
if( len( sys.argv ) == 1 ):
usage()
else:
main( sys.argv[1:] )
3 changes: 2 additions & 1 deletion pip_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pretty_midi
clipboard
clipboard
pyinstaller
2 changes: 2 additions & 0 deletions setup-executable.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@echo off
pyinstaller win32.spec

0 comments on commit 873e4a1

Please sign in to comment.