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