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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
|
"""
This module is an integeral part of the program
MMA - Musical Midi Accompaniment.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Bob van der Poel <bob@mellowood.ca>
"""
# ###################################
# # StrumPattern 1.0 MMA plugin #
# # #
# # written by Ignazio Di Napoli #
# # <neclepsio@gmail.com> #
# ###################################
# We import the plugin utilities
from MMA import pluginUtils as pu
# ###################################
# # Documentation and arguments #
# ###################################
# We add plugin parameters and documentation here.
# The documentation will be printed either calling printUsage() or
# executing "python mma.py -I pluginname".
# I suggest to see the output for this plugin to understand how code
# of this section will be formatted when printed.
# Minimum MMA required version.
pu.setMinMMAVersion(15, 12)
# A short plugin description.
pu.setDescription("Sets a strum pattern for Plectrum tracks.")
# A short author line.
pu.setAuthor("Written by Ignazio Di Napoli <neclepsio@gmail.com>.")
# Since this is a track plugin, we set the track types for which it can
# be used. You can specify more than one. To allow for all track types,
# call setTrackType with no arguments.
# For non-tracks plugin, don't call setTrackType at all.
# Whether the plugin is track or non-track is decided by the entry point,
# but help will use this information.
pu.setTrackType("Plectrum")
# We add the arguments for the command, each with name, default value and a
# small description. A default value of None requires specifying the argument.
pu.addArgument("Pattern", None, "see after")
pu.addArgument("Strum", "5", "strum value to use in sequence (see Plectrum docs)")
pu.addArgument("Volume", "80", "volume for strums, can be specified for each string (see Plectrum docs)")
pu.addArgument("VolumeMuted", "60", "volume for mute, can be specified for each string (see Plectrum docs)")
pu.addArgument("VolumeEmph", "100", "volume for emphatized strums, can be specified for each string (see Plectrum docs)")
pu.addArgument("VolumePick", "90", "volume for single string pick")
# We add a small doc. %NAME% is replaced by plugin name.
pu.setPluginDoc("""
The pattern is specified as a string of dot-separed values, that are equally spaced into the bar.
Values can be:
d downward strum
u upward strum
de downward strum with emphasis
ue upward strum with emphasis
dm downward strum with muted strings
um upward strum with muted strings
x chunk
- do nothing (used to skip to next time division)
If only one-character codes are used, you can avoid dots.
You can specify more bars separed by semicolons (;).
Examples:
Plectrum %NAME% dudududu
Plectrum %NAME% dm.um.dm.um.dm.um.dm.um
Plectrum %NAME% dudududu;12345654
Plectrum %NAME% dudududu, Strum=10
Plectrum %NAME% dudududu, 5, 70, 60, 90, 80
Plectrum %NAME% dudududu, 7, VolumeEmph=90
Each time it's used, %NAME% creates a clone track of the provided one using the voice MutedGuitar for chucks and muted strums.
Its name is the name of the main track with an appended "-Muted", if you need to change it you must do so every time after using %NAME%.
This plugin has been written by Ignazio Di Napoli <neclepsio@gmail.com>.
Version 1.0.
""")
# ###################################
# # Entry points #
# ###################################
# This prints help when MMA is called with -I switch.
# Cannot import plugin_utils directly because it wouldn't recognize which
# plugin is executing it.
def printUsage():
pu.printUsage()
# This is a track plugin, so we define trackrun(trackname, line).
# For non-track plugins we use run(line).
# When using this library, only one of the two can be used.
def trackRun(trackname, line):
# We check if track type is correct.
pu.checkTrackType(trackname)
# We parse the arguments. Errors are thrown if something is wrong,
# printing the correct usage on screen. Default are used if needed.
# parseCommandLine also takes an optional boolean argument to allow
# using of arguments not declared with pu.addArgument, default is False.
args = pu.parseCommandLine(line)
# This is how we access arguments.
pattern = args["Pattern"]
strum = args["Strum"]
volumeN = args["Volume"]
volumeM = args["VolumeMuted"]
volumeE = args["VolumeEmph"]
volumeP = args["VolumePick"]
# This is the logic for the plugin.
all_normal = ""
all_muted = ""
for bar_pattern in pattern.split(";"):
if "." in bar_pattern:
bar_pattern = bar_pattern.lower().split(".")
else:
# you can avoid commas when not using ue, ux, de, dx
bar_pattern = bar_pattern.lower()
strums_normal = []
strums_muted = []
step = float(pu.getSysVar("TIME"))/len(bar_pattern)
for i, c in enumerate(bar_pattern):
t = 1+step*i
if c == "u":
strums_normal.append("{:0.4} -{} {}".format(t, strum, volumeN))
elif c == "ue":
strums_normal.append("{:0.4} -{} {}".format(t, strum, volumeE))
elif c == "um":
strums_normal.append("{:0.4} 0 0".format(t))
strums_muted.append("{:0.4} -{} {}".format(t, strum, volumeM))
elif c == "d":
strums_normal.append("{:0.4} +{} {}".format(t, strum, volumeN))
elif c == "de":
strums_normal.append("{:0.4} +{} {}".format(t, strum, volumeE))
elif c == "dm":
strums_normal.append("{:0.4} 0 0".format(t))
strums_muted.append("{:0.4} +{} {}".format(t, strum, volumeM))
elif c == "x":
strums_normal.append("{:0.4} 0 0".format(t))
strums_muted.append("{:0.4} 0 {}".format(t, volumeM))
elif c == "0":
strums_normal.append("{:0.4} 0 0".format(t))
elif c.lstrip("0").isdigit():
for s in c:
strums_normal.append("{:0.4} 0 {}:{}".format(t, s, volumeP))
elif c == "-":
pass
else:
#printUsage()
pu.error("{}: unrecognized command in strum pattern: '{}'.".format(pu.getName(), c))
bar_normal = ("{" + "; ".join(strums_normal) + ";}") if len(strums_normal) > 0 else "z"
bar_muted = ("{" + "; ".join(strums_muted) + ";}") if len(strums_muted) > 0 else "z"
all_normal += bar_normal + " "
all_muted += bar_muted + " "
# If you don't send all the commands together the result is commands
# are reversed since each is pushed as the very next command to be executed.
# So we save all the commands (with addCommand) and send them at the end
# (with sendCommands).
pu.addCommand("{} Sequence {}".format(trackname, all_normal))
pu.addCommand("{}-Muted SeqClear".format(trackname))
pu.addCommand("{}-Muted Copy {}".format(trackname, trackname))
pu.addCommand("{}-Muted Voice MutedGuitar".format(trackname))
pu.addCommand("{}-Muted Sequence {}".format(trackname, all_muted))
pu.sendCommands()
|