1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# MusE external midi processing script
# By: Robert Jonsson 2012
# Rhythm1
#=============================================================================
# MusE
# Linux Music Editor
# $Id:$
#
# Copyright (C) 2002-2011 by Werner Schweer and others
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#=============================================================================
import sys,time
testFile = open(sys.argv[1],"r")
inputEvents = testFile.readlines()
testFile.close()
outputEvents=[]
BAR=0
BEAT=0
BEATLEN=0
QUANTLEN=0
PARTLEN=0
hihatNote="42"
kickNote="35"
snareNote="38"
length="1"
velocity="100"
#loop through events reading configuration
for line in inputEvents:
outputEvents.append(line)
if line.startswith('TIMESIG'):
tag,bar,beat = line.split(' ')
BAR = int(bar)
BEAT = int(beat)
if line.startswith('BEATLEN'):
tag,beatLen = line.split(' ')
BEATLEN=int(beatLen)
if line.startswith('QUANTLEN'):
tag,quantLen = line.split(' ')
QUANTLEN = int(quantLen)
if line.startswith('PART'):
tag,start,end = line.split(' ')
PARTLEN = int(end) - int(start)
######################################
######################################
for ticking in range(0,PARTLEN):
if ticking % (BEATLEN * 4) == 0:
newline = "NOTE " + str(ticking) + " " + kickNote + " " + length + " " + velocity + "\n"
outputEvents.append(newline)
if ticking % (BEATLEN * 4) - (BEATLEN * 2) == 0:
newline = "NOTE " + str(ticking) + " " + snareNote + " " + length + " " + velocity + "\n"
outputEvents.append(newline)
if ticking % (BEATLEN) == 0:
newline = "NOTE " + str(ticking) + " " + hihatNote + " " + length + " " + velocity + "\n"
outputEvents.append(newline)
testFile = open(sys.argv[1],"w")
testFile.writelines(outputEvents)
testFile.close()
#testFile2 = file("/home/ddskrjo/o2.txt","w")
#testFile2.writelines(outputEvents)
#testFile2.close()
|