Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Reverse script and introduce new TYPE script tag #1071

Merged
merged 5 commits into from May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ChangeLog
@@ -1,3 +1,5 @@
04.05.2022
- Reverse script that reverses MIDI and DRUM parts incl controllers. (Staffan)
03.05.2022
- Reuploaded script (Fix issue 1037: Time stretching/shrinking for midi/drum parts.) (Staffan)
26.04.2022
Expand Down
9 changes: 9 additions & 0 deletions src/muse/scripts.cpp
Expand Up @@ -2,6 +2,7 @@
#include <iostream>

#include "scripts.h"
#include "track.h"
#include "part.h"
#include "song.h"
#include "debug.h"
Expand Down Expand Up @@ -81,6 +82,14 @@ void Scripts::executeScript(QWidget *parent, const char* scriptfile, PartList* p
writeStringToFile(fp,tempStr);
sprintf(tempStr, "QUANTLEN %d\n", quant);
writeStringToFile(fp,tempStr);
MidiTrack *track = part->track();
if (track->type() == Track::MIDI)
{
sprintf(tempStr, "TYPE MIDI\n");
} else if (track->type() == Track::DRUM) {
sprintf(tempStr, "TYPE DRUM\n");
}
writeStringToFile(fp,tempStr);

if (MusEGlobal::debugMsg)
std::cout << "Events in part " << part->events().size() << std::endl;
Expand Down
4 changes: 3 additions & 1 deletion src/share/scripts/CMakeLists.txt
Expand Up @@ -31,8 +31,10 @@ file(GLOB script_files
RandomQuantize1
RandomPosition1
RemoveAftertouch
RemoveShortEvents
RemoveShortEvents
Reverse
Rhythm1
SpeedChange
SpeedHalf
SpeedDouble
SwingQuantize1
Expand Down
9 changes: 5 additions & 4 deletions src/share/scripts/README.txt
@@ -1,4 +1,4 @@
MusE midi event scripting format 0.6
MusE midi event scripting format 0.7
====================================

= INTRODUCTION
Expand All @@ -21,13 +21,14 @@ to the same file.

The tags that may occur in the file sent to the script are:
TIMESIG <n> <z>
PARTLEN <len in ticks of the current Part>
PART <start tick> <len in ticks>
BEATLEN <len in ticks of a beat>
QUANTLEN <len in ticks of the current quantization>
TYPE <track type of part, can be MIDI or DRUM>
NOTE <tick> <pitch> <len in ticks> <velocity>
CONTROLLER <tick> <a> <b> <c>

TIMESIG, PARTLEN, BEATLEN and QUANTLEN are there for informational purposes, to
TIMESIG, PART, BEATLEN, QUANTLEN and TYPE are there for informational purposes, to
make some transformations possible. e.g. quantization, beat delay.

NOTE and CONTROLLER are the ones that are read back into MusE when the filter
Expand Down Expand Up @@ -59,7 +60,7 @@ templates for creating more advanced scripts.

- DoNothing, just reads the input file, loops through the lines and outputs
them again.
- DoubleSpeed, reads all notes and outputs them with all ticks divided
- SpeedDouble, reads all notes and outputs them with all ticks divided
in half.
- RemoveShortEvents, a script with a GUI in PyQt which removes events
shorter then the set note length
Expand Down
62 changes: 62 additions & 0 deletions src/share/scripts/Reverse
@@ -0,0 +1,62 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# MusE external midi processing script
# By: Staffan Melin
#=============================================================================
# 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()

for line in inputEvents:
if line.startswith('PART'):
tag, startticks, partticks = line.split(' ')
if line.startswith('TYPE'):
tag, tracktype = line.split(' ')
if tracktype[-1] == '\n':
tracktype = tracktype[:-1]

outputEvents=[]
#loop through events
for line in inputEvents:
if line.startswith('NOTE'):
tag, tick, pitch, length, velocity = line.split(' ')
if tracktype == 'MIDI':
newtick = int(partticks) - int(tick) - int(length)
else:
newtick = int(partticks) - int(tick)
newline = tag + " " + str(newtick) + " " + pitch + " " + length + " " + velocity
outputEvents.append(newline)
elif line.startswith('CONTROLLER'):
tag, tick, a, b, c = line.split(' ')
newtick = int(partticks) - int(tick)
newline = tag + " " + str(newtick) + " " + a + " " + b + " " + c
outputEvents.append(newline)


testFile = open(sys.argv[1],"w")
testFile.writelines(outputEvents)
testFile.close()