1#!/usr/local/bin/python3.8 2# -*- coding: utf-8 -*- 3# MusE external midi processing script 4# By: Robert Jonsson 2014 5# TEMPO delay 6#============================================================================= 7# MusE 8# Linux Music Editor 9# $Id:$ 10# 11# Copyright (C) 2002-2011 by Werner Schweer and others 12# 13# This program is free software; you can redistribute it and/or modify 14# it under the terms of the GNU General Public License 15# as published by the Free Software Foundation; either version 2 16# of the License, or (at your option) any later version. 17# 18# This program is distributed in the hope that it will be useful, 19# but WITHOUT ANY WARRANTY; without even the implied warranty of 20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21# GNU General Public License for more details. 22# 23# You should have received a copy of the GNU General Public License 24# along with this program; if not, write to the 25# Free Software Foundation, Inc., 26# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27#============================================================================= 28 29 30import sys,time 31from PyQt5.QtWidgets import QApplication, QWidget, QComboBox, QLabel, QSpinBox, QPushButton, QGridLayout 32 33class TempoDelay(QWidget): 34 def __init__(self, parent=None): 35 QWidget.__init__(self, parent) 36 37 self.setWindowTitle('Tempo delay') 38 39 title = QLabel('Delay time:') 40 self.timeEdit = QComboBox() 41 self.timeEdit.addItem('1/1',1) 42 self.timeEdit.addItem('1/2',2) 43 self.timeEdit.addItem('1/4',4) 44 self.timeEdit.addItem('1/8',8) 45 self.timeEdit.addItem('1/16',16) 46 self.timeEdit.addItem('1/32',32) 47 self.timeEdit.setCurrentIndex(3) 48 49 numLabel = QLabel('Number of delays:') 50 self.numEntry = QSpinBox() 51 self.numEntry.setMinimum(1) 52 self.numEntry.setValue(1) 53 54 print ("setting execute") 55 button = QPushButton("Execute") 56 button.clicked.connect(self.execute) 57 58 grid = QGridLayout() 59 grid.setSpacing(3) 60 61 grid.addWidget(title, 1, 0) 62 grid.addWidget(self.timeEdit, 1, 1) 63 grid.addWidget(numLabel, 2, 0) 64 grid.addWidget(self.numEntry, 2, 1) 65 66 grid.addWidget(button, 3, 1) 67 68 self.setLayout(grid) 69 self.resize(200, 100) 70 button.setFocus() 71 72 def execute(self): 73 74 testFile = open(sys.argv[1],"r") 75 inputEvents = testFile.readlines() 76 testFile.close() 77 78 numDelay = self.numEntry.value() 79 beatDiv = self.timeEdit.itemData(self.timeEdit.currentIndex()) 80 delayLength=0 # fill in when we get the beat size value 81 82 outputEvents=[] 83 84 #get beat length to calculate minimum length of event 85 for line in inputEvents: 86 if line.startswith('BEATLEN'): 87 tag,tick = line.split(' ') 88 delayLength=int(tick)/beatDiv 89 break 90 91 #loop through events 92 for line in inputEvents: 93 if line.startswith('NOTE'): 94 tag,tick,note,length,velocity = line.split(' ') 95 outputEvents.append(line) 96 for v in range(numDelay): 97 outputEvents.append("%s %d %s %s %d\n"%(tag,int(tick)+delayLength*(v+1),note,length,int(velocity)/(v+2))) 98 99 else: 100 outputEvents.append(line) 101 102 103 testFile = open(sys.argv[1],"w") 104 testFile.writelines(outputEvents) 105 testFile.close() 106 107 108 quit() 109 110app = QApplication(sys.argv) 111qb = TempoDelay() 112qb.show() 113sys.exit(app.exec_()) 114