@@ -0,0 +1,201 @@ | |||
import * as std from "std"; | |||
function usage(msg) | |||
{ | |||
if ( msg ) | |||
print(msg); | |||
print("usage: ./qjs " + scriptArgs[0] + " [-p] -i <input.json> -s <script.js> -o <output.json>"); | |||
return 1; | |||
} | |||
//--------------------------------------------------------------------- | |||
// no lf, no space | |||
const pflags_def = [ [ false, false ] ]; | |||
function get_pflags(jso) | |||
{ | |||
if ( jso === "fcode" || jso === "bcode" ) | |||
{ | |||
return [ | |||
[ true, false ] | |||
]; | |||
} | |||
else if ( jso === "forward" || jso === "backward" ) | |||
{ | |||
return [ | |||
[ false, false ], | |||
[ true, false ], | |||
[ true, true ] | |||
]; | |||
} | |||
return pflags_def; | |||
} | |||
function print_lf(o_file, level) | |||
{ | |||
o_file.puts('\n'); | |||
o_file.printf("%*s", level * 2, ""); | |||
} | |||
function print_space(o_file) | |||
{ | |||
o_file.puts(' '); | |||
} | |||
function output_lf(o_file, pflags, level) | |||
{ | |||
const json_pflags_no_lf = pflags[0]; | |||
const json_pflags_no_space = pflags[1]; | |||
if ( !json_pflags_no_lf ) | |||
print_lf(o_file, level); | |||
else if ( !json_pflags_no_space ) | |||
print_space(o_file); | |||
} | |||
function json_print_element(o_file, jso, pflags, level) | |||
{ | |||
if ( typeof jso === "object" ) | |||
{ | |||
if ( jso === null ) | |||
{ | |||
o_file.puts("null"); | |||
} | |||
else if ( Array.isArray(jso) ) | |||
{ | |||
const pflags0 = pflags[0]; | |||
const pflags1 = pflags.slice(1); | |||
o_file.puts('['); | |||
for ( let i = 0; i < jso.length; i++ ) | |||
{ | |||
if ( i != 0 ) | |||
o_file.puts(','); | |||
output_lf(o_file, pflags0, level+1); | |||
json_print_element(o_file, jso[i], pflags1, level+1); | |||
} | |||
output_lf(o_file, pflags0, level); | |||
o_file.puts(']'); | |||
} | |||
else | |||
{ | |||
let i = 0; | |||
o_file.puts('{'); | |||
for ( const key in jso ) | |||
{ | |||
if ( i++ != 0 ) | |||
o_file.puts(','); | |||
print_lf(o_file, level+1); | |||
o_file.puts(JSON.stringify(key)); | |||
o_file.puts(':'); | |||
json_print_element(o_file, jso[key], get_pflags(key), level+1); | |||
} | |||
print_lf(o_file, level); | |||
o_file.puts('}'); | |||
} | |||
} | |||
else | |||
{ | |||
o_file.puts(JSON.stringify(jso)); | |||
} | |||
} | |||
function json_fputs(o_file, jso) | |||
{ | |||
json_print_element(o_file, jso, pflags_def, 0); | |||
o_file.puts('\n'); | |||
} | |||
/////////////////////////////////////////////////////////////////////// | |||
// global variables for the script | |||
var json_stream = null; | |||
var json_frame = null; | |||
function run_script(s_path, i_path, o_path, do_pretty) | |||
{ | |||
// load input JSON | |||
print("[+] loading input JSON file '" + i_path + "'") | |||
let i_file = std.open(i_path, "r"); | |||
if ( !i_file ) | |||
return usage("could not open input file '" + i_path + "'"); | |||
let str = i_file.readAsString(); | |||
let json_root = JSON.parse(str); | |||
if ( !json_root ) | |||
return usage("error parsing input file '" + i_path + "'"); | |||
i_file.close(); | |||
// will error out on exception | |||
print("[+] running script '" + s_path + "' on JSON data") | |||
std.loadScript(s_path); | |||
// for each stream (normally there is only one stream of interest) | |||
let streams = json_root["streams"]; | |||
for ( let i = 0; i < streams.length; i++ ) | |||
{ | |||
let stream = streams[i]; | |||
json_stream = stream; | |||
// for each frame in the stream | |||
let frames = stream["frames"]; | |||
for ( let j = 0; j < frames.length; j++ ) | |||
{ | |||
let frame = frames[j]; | |||
json_frame = frame; | |||
glitch_frame(frame); | |||
} | |||
} | |||
// open input JSON | |||
print("[+] writing " + (do_pretty ? "prettified " : "") + "output JSON file '" + o_path + "'") | |||
let o_file = std.open(o_path, "w+"); | |||
if ( !o_file ) | |||
return usage("could not open output file '" + o_path + "'"); | |||
if ( do_pretty ) | |||
json_fputs(o_file, json_root); | |||
else | |||
o_file.puts(JSON.stringify(json_root)); | |||
o_file.close(); | |||
return 0; | |||
} | |||
function main(argc, argv) | |||
{ | |||
let i_path = null; | |||
let o_path = null; | |||
let s_path = null; | |||
let do_pretty = false; | |||
for ( let i = 1; i < argc; ) | |||
{ | |||
let opt = argv[i++]; | |||
if ( opt == "-i" ) | |||
{ | |||
if ( i == argc ) | |||
return usage("parameter missing for option '-i'"); | |||
i_path = argv[i++]; | |||
} | |||
else if ( opt == "-o" ) | |||
{ | |||
if ( i == argc ) | |||
return usage("parameter missing for option '-o'"); | |||
o_path = argv[i++]; | |||
} | |||
else if ( opt == "-s" ) | |||
{ | |||
if ( i == argc ) | |||
return usage("parameter missing for option '-s'"); | |||
s_path = argv[i++]; | |||
} | |||
else if ( opt == "-p" ) | |||
{ | |||
do_pretty = true; | |||
} | |||
else | |||
{ | |||
return usage("unknown option '" + opt + "'"); | |||
} | |||
} | |||
if ( !s_path || !i_path || !o_path ) | |||
return usage(); | |||
return run_script(s_path, i_path, o_path, do_pretty); | |||
} | |||
main(scriptArgs.length, scriptArgs, this); |
@@ -0,0 +1,131 @@ | |||
#!/usr/bin/env python | |||
# run script on frames from input file: | |||
# ffglitch -i <file> -f <features> -s <script> -o <file> | |||
import argparse | |||
import os | |||
import subprocess | |||
import sys | |||
import tempfile | |||
import hashlib | |||
# Load json library (try first with fastest one) | |||
try: | |||
import orjson | |||
_json = orjson | |||
_dumps_ftype = 'wb' | |||
except: | |||
import json | |||
_json = json | |||
_dumps_ftype = 'w' | |||
parser = argparse.ArgumentParser() | |||
parser.add_argument('-i', metavar="<file>", dest='input', required=True, help='input media file') | |||
parser.add_argument('-f', metavar="<feature>", dest='feature', required=True, help='select feature to glitch') | |||
parser.add_argument('-s', metavar="<file>", dest='script', required=True, help='script to glitch frames') | |||
parser.add_argument('-o', metavar="<file>", dest='output', required=True, help='output media file') | |||
parser.add_argument('-v', action="store_true", dest='verbose', required=False, help='verbose output') | |||
parser.add_argument('-k', action="store_true", dest='keep', required=False, help='do not delete temporary JSON file') | |||
args = parser.parse_args() | |||
# Handle verbosity | |||
if args.verbose: | |||
stderr = sys.stdout | |||
else: | |||
stderr = open(os.devnull, 'w') | |||
# Generate input json file name | |||
json_in = os.path.splitext(args.input)[0] + ".json" | |||
# Check that input file name does not end in .json | |||
if json_in == args.input: | |||
raise ValueError('Input file name must not end in .json') | |||
# Function to get sha1sum of file | |||
def calc_sha1sum(filename): | |||
h = hashlib.sha1() | |||
b = bytearray(128*1024) | |||
mv = memoryview(b) | |||
with open(filename, 'rb', buffering=0) as f: | |||
for n in iter(lambda : f.readinto(mv), 0): | |||
h.update(mv[:n]) | |||
return h.hexdigest() | |||
# Try to read input json file | |||
json_root = None | |||
try: | |||
with open(json_in, 'r') as f: | |||
print("[+] checking existing JSON file '%s'" % json_in) | |||
json_root = _json.loads(f.read()) | |||
# check features | |||
features = json_root["features"] | |||
if len(features) != 1 or features[0] != args.feature: | |||
json_root = None | |||
print("[-] feature '%s' not found in '%s'" % (args.feature, json_in)) | |||
# check sha1sum | |||
sha1sum = json_root["sha1sum"] | |||
if len(sha1sum) != 40 or sha1sum != calc_sha1sum(args.input): | |||
json_root = None | |||
print("[-] sha1sum mismatch for '%s' in '%s'" % (args.input, json_in)) | |||
if json_root is not None: | |||
print("[+] OK") | |||
except IOError: | |||
pass | |||
ffedit_path = None | |||
def run_ffedit(cmd): | |||
global ffedit_path | |||
if ffedit_path == None: | |||
dir_path = os.path.dirname(os.path.realpath(__file__)) | |||
ffedit_path = [os.path.join(dir_path, "ffedit")] | |||
cmd = ffedit_path + cmd | |||
if args.verbose: | |||
print("[v] $ %s" % ' '.join(cmd)) | |||
return subprocess.check_output(cmd, stderr=stderr) | |||
# First pass (export data) | |||
if json_root is None: | |||
print("[+] exporting feature '%s' to '%s'" % (args.feature, json_in)) | |||
run_ffedit([args.input, "-f", args.feature, "-e", json_in]) | |||
with open(json_in, 'r') as f: | |||
json_root = _json.loads(f.read()) | |||
# Run script on JSON data. | |||
print("[+] running script '%s' on JSON data" % args.script) | |||
with open(args.script) as infile: | |||
exec(infile.read()) | |||
json_stream = None | |||
json_frame = None | |||
# for each stream (normally there is only one stream of interest) | |||
for stream in json_root["streams"]: | |||
json_stream = stream | |||
# for each frame in the stream | |||
for frame in stream["frames"]: | |||
json_frame = frame | |||
# if ffedit exported motion vectors | |||
if args.feature in frame: | |||
glitch_frame(frame[args.feature]) | |||
# Dump modified JSON data to temporary file. | |||
json_fd, json_out = tempfile.mkstemp(prefix='ffglitch_', suffix='.json') | |||
json_fp = os.fdopen(json_fd, _dumps_ftype) | |||
print("[+] dumping modified data to '%s'" % json_out) | |||
json_fp.write(_json.dumps(json_root)) | |||
json_fp.close() | |||
# Second pass (apply data). | |||
print("[+] applying modified data to '%s'" % args.output) | |||
ok = False | |||
try: | |||
run_ffedit([args.input, "-f", args.feature, "-a", json_out, args.output]) | |||
ok = True | |||
except subprocess.CalledProcessError as grepexc: | |||
vstr = " (rerun FFglitch with '-v')" if not args.verbose else "" | |||
print("[-] something went wrong%s" % vstr) | |||
# Remove temporary JSON file. | |||
if ok and not args.keep: | |||
os.unlink(json_out) | |||
else: | |||
print("[+] not deleting temporary file '%s'" % json_out) |
@@ -0,0 +1,44 @@ | |||
<Technical info about this build>: | |||
FFglitch 0.9.4 | |||
macOS | |||
64-bit | |||
You can get the source code here: | |||
http://ffglitch.org/pub/src/ffglitch-0.9.4.tar.xz | |||
FFglitch also includes the following libraries: | |||
quickjs 2021-03-27 <https://bellard.org/quickjs> | |||
zlib 1.2.11 <http://zlib.net> | |||
Xvid 1.3.6 <https://labs.xvid.com> | |||
<What?> | |||
FFglitch is a multimedia bitstream editor, based on the open-source | |||
project FFmpeg <http://ffmpeg.org>. | |||
For more information, go to <http://ffglitch.org>. | |||
<Who?> | |||
Hi, I’m Ramiro Polla <https://github.com/ramiropolla>. | |||
On my free time I like to work on useless projects. | |||
<GPL boilerplate>: | |||
Copyright (C) 2018-2021 Ramiro Polla | |||
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. |
@@ -1,2 +1,2 @@ | |||
//globals | |||
uptime = 117266253 | |||
uptime = 117464831 |
@@ -1688,13 +1688,15 @@ class BROKENCOLORROT extends Shader { | |||
*/ | |||
class POSTER extends Shader { | |||
int levels = 2; | |||
POSTER() { | |||
name = "fxPosterize"; | |||
params.add(new Param("levels", INTVAL, 2, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
} | |||
void apply() { | |||
levels = (int)params.get(0).value; | |||
canvas.beginDraw(); | |||
canvas.filter(POSTERIZE, (int)params.get(0).value); | |||
canvas.filter(POSTERIZE, levels); | |||
canvas.endDraw(); | |||
} | |||
} | |||
@@ -4379,7 +4381,6 @@ class WEBPCORRUPTION extends Shader { | |||
img.resize(rw, rh); | |||
} | |||
int probparam = (int)params.get(0).value; | |||
int iterations = (int)params.get(1).value; | |||
img = canvas.get(); | |||
canvas.beginDraw(); | |||
canvas.image(img, canvas.width/2, canvas.height/2); | |||
@@ -4403,10 +4404,10 @@ class WEBPCORRUPTION extends Shader { | |||
} | |||
canvas.save(dataPath("")+"/webp_orig.png"); //save as png | |||
int failCount = 0; | |||
while (!runCommand(convertToPNG) && failCount < 25) { | |||
while ((runCommand(convertToPNG) != 0) && failCount < 25) { | |||
failCount ++; | |||
println("Trying to convert..."); | |||
while (!runCommand(convertToWebp)) { | |||
while (runCommand(convertToWebp) != 0) { | |||
println("Conversion failed, trying again..."); | |||
} | |||
brokenfile = loadBytes(dataPath("")+"/webp_orig.webp"); //and reload. just in case it wasnt a jpg. | |||
@@ -4440,7 +4441,7 @@ class WEBPCORRUPTION extends Shader { | |||
} | |||
*/ | |||
} | |||
if(failCount == 50) println("Failed 50 times, skipping webp glitch"); | |||
if (failCount == 25) println("Failed 50 times, skipping webp glitch"); | |||
else img = loadImage(dataPath("") + "/webp_glitched.png"); | |||
//launch(dataPath("") + "/webpdecode.command"); | |||
@@ -4467,3 +4468,409 @@ class WEBPCORRUPTION extends Shader { | |||
return result; | |||
} | |||
} | |||
/* | |||
SOX | |||
*/ | |||
class SOX extends Shader { | |||
PImage img; | |||
int rw, rh; | |||
int depth = 8; | |||
int iterations = 1; | |||
int samplerate = 44100; | |||
int channels = 1; | |||
String coding = "a-law"; | |||
String type = "al"; | |||
int encoding = 0; | |||
boolean rgbyuv = true; | |||
boolean do_blend = false; | |||
int blend_type = 1; | |||
String[] effectParams; | |||
SOX() { | |||
} | |||
void setSoxParams() { | |||
rw = canvas.width; | |||
rh = canvas.height; | |||
img = createImage(rw, rh, ARGB); | |||
params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM})); | |||
directionParamIndex = 0; | |||
params.add(new Param("iterations", INTVAL, 1, 10, new int[]{RANDOM})); | |||
params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); | |||
params.add(new Param("blend type", INTVAL, 0, blends.length-1, new int[]{RANDOM})); | |||
params.add(new Param("bitdepth (8, 16, 24)", INTVAL, 1, 3, new int[]{RANDOM})); | |||
params.add(new Param("samplerate", INTVAL, 1400, 200000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("encoding", INTVAL, 0, 7, new int[]{RANDOM})); | |||
params.add(new Param("yuv / rgb", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); | |||
params.add(new Param("channels (mono / stereo)", INTVAL, 1, 2, new int[]{RANDOM, SQUAR})); | |||
} | |||
void apply() { | |||
iterations = (int)params.get(1).value; | |||
do_blend = boolean((int)params.get(2).value); | |||
blend_type = blends[(int)params.get(3).value]; | |||
depth = (int)params.get(4).value * 8; | |||
samplerate = (int)params.get(5).value; | |||
encoding = (int)params.get(6).value; | |||
switch(encoding) { | |||
case(0): | |||
type = "s8"; | |||
coding = "signed-integer"; | |||
break; | |||
case(1): | |||
type = "u8"; | |||
coding = "unsigned-integer"; | |||
break; | |||
case(2): | |||
type = "s16"; | |||
coding = "signed-integer"; | |||
break; | |||
case(3): | |||
type = "u16"; | |||
coding = "unsigned-integer"; | |||
break; | |||
case(4): | |||
type = "s24"; | |||
coding = "signed-integer"; | |||
break; | |||
case(5): | |||
type = "u24"; | |||
coding = "unsigned-integer"; | |||
break; | |||
case(6): | |||
type = "al"; | |||
coding = "a-law"; | |||
break; | |||
case(7): | |||
type = "ul"; | |||
coding = "u-law"; | |||
break; | |||
default: | |||
type = "f32"; | |||
coding = "float"; | |||
break; | |||
} | |||
rgbyuv = boolean((int)params.get(7).value); | |||
channels = (int)params.get(8).value; | |||
getParams(); | |||
if (rw != canvas.width || rh != canvas.height) { | |||
rw = canvas.width; | |||
rh = canvas.height; | |||
img.resize(rw, rh); | |||
} | |||
img = canvas.get(); | |||
canvas.beginDraw(); | |||
canvas.image(img, canvas.width/2, canvas.height/2); | |||
File oldImage = new File(dataPath("")+"/sox.raw"); | |||
if (oldImage.exists()) { | |||
oldImage.delete(); | |||
} | |||
oldImage = new File(dataPath("")+"/sox.png"); | |||
if (oldImage.exists()) { | |||
oldImage.delete(); | |||
} | |||
oldImage = new File(dataPath("")+"/sox_sonified.raw"); | |||
if (oldImage.exists()) { | |||
oldImage.delete(); | |||
} | |||
canvas.save(dataPath("")+"/sox.png"); //save as png | |||
String[] convertToRAW = new String[]{"/usr/local/bin/convert", "-verbose", dataPath("") + "/sox.png", "-depth", str(depth), ((rgbyuv) ? "rgb" : "yuv") + ":" + dataPath("") + "/sox.raw"}; | |||
String[] soxCall = new String[]{"/usr/local/bin/sox", "-r", str(samplerate), "-e", coding, "-b", "8", "-c", "2", "-t", type, dataPath("") + "/sox.raw", dataPath("") + "/sox_sonified.raw"}; | |||
String[] sonify = concat(soxCall, effectParams); | |||
String[] convertToPNG = new String[]{"/usr/local/bin/convert", "-verbose", "-size", str(rw) + "x" + str(rh), "-depth", str(depth), ((rgbyuv) ? "rgb" : "yuv") + ":" + dataPath("") + "/sox_sonified.raw", dataPath("") + "/sox.png"}; | |||
for (int i = 0; i < iterations; i++) { | |||
if (runCommand(convertToRAW) != 0) { | |||
println("Conversion to RAW failed"); | |||
} | |||
if (runCommand(sonify) != 0) { | |||
println("Sonification failed"); | |||
} | |||
if (runCommand(convertToPNG) != 0) { | |||
println("Conversion to PNG failed"); | |||
} | |||
img = loadImage(dataPath("") + "/sox.png"); | |||
} | |||
if (do_blend) { | |||
canvas.blend(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height, blend_type); | |||
} else { | |||
canvas.image(img, canvas.width/2, canvas.height/2); | |||
} | |||
canvas.endDraw(); | |||
} | |||
void getParams() { | |||
} | |||
} | |||
/* | |||
SOXECHO | |||
NEEDS FIXING | |||
*/ | |||
class SOXECHO extends SOX { | |||
float gainin = 0.8; | |||
float gainout = 0.8; | |||
float delay = 0.8; | |||
float decay = 0.8; | |||
SOXECHO() { | |||
name = "fxSoxEcho"; | |||
setSoxParams(); | |||
params.add(new Param("gain in", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("gain out", FLOATVAL, 0.01, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("delay", FLOATVAL, 0.01, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("decay", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
} | |||
void getParams() { | |||
gainin = params.get(9).value; | |||
gainout = params.get(10).value; | |||
delay = params.get(11).value; | |||
decay = params.get(12).value; | |||
effectParams = new String[]{"echo", str(gainin), str(gainout), str(delay), str(decay)}; | |||
} | |||
} | |||
/* | |||
SOXALLPASS | |||
*/ | |||
class SOXALLPASS extends SOX { | |||
String hkqo = "h"; | |||
int frequency = 100; | |||
int widt = 100; | |||
SOXALLPASS() { | |||
name = "fxSoxAllpass"; | |||
setSoxParams(); | |||
params.add(new Param("frequency", INTVAL, 1, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
} | |||
void getParams() { | |||
frequency = (int)params.get(9).value; | |||
widt = (int)params.get(10).value; | |||
switch((int)params.get(11).value) { | |||
case(0): | |||
hkqo = "h"; | |||
break; | |||
case(1): | |||
hkqo = "k"; | |||
break; | |||
case(2): | |||
hkqo = "q"; | |||
break; | |||
default: | |||
hkqo = "o"; | |||
break; | |||
} | |||
effectParams = new String[]{"allpass", str(frequency), str(widt) + hkqo}; | |||
} | |||
} | |||
/* | |||
SOXBAND | |||
*/ | |||
class SOXBAND extends SOX { | |||
String hkqo = "h"; | |||
int center = 100; | |||
int widt = 100; | |||
boolean n; | |||
SOXBAND() { | |||
name = "fxSoxBand"; | |||
setSoxParams(); | |||
params.add(new Param("center", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("-n", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); | |||
} | |||
void getParams() { | |||
center = (int)params.get(9).value; | |||
widt = (int)params.get(10).value; | |||
switch((int)params.get(11).value) { | |||
case(0): | |||
hkqo = "h"; | |||
break; | |||
case(1): | |||
hkqo = "k"; | |||
break; | |||
case(2): | |||
hkqo = "q"; | |||
break; | |||
default: | |||
hkqo = "o"; | |||
break; | |||
} | |||
n = boolean((int)params.get(12).value); | |||
effectParams = new String[]{ "band", (n ? "-n " : "") + str(center), str(widt) + hkqo}; | |||
} | |||
} | |||
/* | |||
SOXBANDPASS | |||
*/ | |||
class SOXBANDPASS extends SOX { | |||
int widt, frequency; | |||
String hkqo; | |||
boolean c; | |||
SOXBANDPASS() { | |||
name = "soxBandPass"; | |||
setSoxParams(); | |||
params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("-c", INTVAL, 0, 1, new int[]{RANDOM, SQUAR})); | |||
} | |||
void getParams() { | |||
frequency = (int)params.get(9).value; | |||
widt = (int)params.get(10).value; | |||
switch((int)params.get(11).value) { | |||
case(0): | |||
hkqo = "h"; | |||
break; | |||
case(1): | |||
hkqo = "k"; | |||
break; | |||
case(2): | |||
hkqo = "q"; | |||
break; | |||
default: | |||
hkqo = "o"; | |||
break; | |||
} | |||
c = boolean((int)params.get(12).value); | |||
effectParams = new String[]{"bandpass", (c ? "-c " : "") + str(frequency), str(widt) + hkqo}; | |||
} | |||
} | |||
/* | |||
SOXBANDREJECT | |||
*/ | |||
class SOXBANDREJECT extends SOX { | |||
int widt, frequency; | |||
String hkqo; | |||
SOXBANDREJECT() { | |||
name = "soxBandReject"; | |||
setSoxParams(); | |||
params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
} | |||
void getParams() { | |||
frequency = (int)params.get(9).value; | |||
widt = (int)params.get(10).value; | |||
switch((int)params.get(11).value) { | |||
case(0): | |||
hkqo = "h"; | |||
break; | |||
case(1): | |||
hkqo = "k"; | |||
break; | |||
case(2): | |||
hkqo = "q"; | |||
break; | |||
default: | |||
hkqo = "o"; | |||
break; | |||
} | |||
effectParams = new String[]{"bandreject", str(frequency), str(widt) + hkqo}; | |||
} | |||
} | |||
/* | |||
SOXBASS | |||
*/ | |||
class SOXBASS extends SOX { | |||
int widt, frequency, gain; | |||
float seconds; | |||
String hkqo; | |||
SOXBASS() { | |||
name = "soxBass"; | |||
setSoxParams(); | |||
params.add(new Param("gain", INTVAL, 1, 100, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
params.add(new Param("seconds", FLOATVAL, 0.001, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
} | |||
void getParams() { | |||
gain = (int)params.get(9).value; | |||
frequency = (int)params.get(10).value; | |||
widt = (int)params.get(11).value; | |||
switch((int)params.get(12).value) { | |||
case(0): | |||
hkqo = "h"; | |||
break; | |||
case(1): | |||
hkqo = "k"; | |||
break; | |||
case(2): | |||
hkqo = "q"; | |||
break; | |||
default: | |||
hkqo = "o"; | |||
break; | |||
} | |||
seconds = params.get(13).value; | |||
effectParams = new String[]{"bass", str(gain), str(frequency), str(widt) + hkqo}; | |||
} | |||
} | |||
/* | |||
SOXBEND | |||
*/ | |||
class SOXBEND extends SOX { | |||
int framerate, oversample, start, cents, end; | |||
SOXBEND() { | |||
name = "soxBend"; | |||
setSoxParams(); | |||
//params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
//params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
//params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); | |||
} | |||
void getParams() { | |||
//frequency = (int)params.get(9).value; | |||
//widt = (int)params.get(10).value; | |||
//effectParams = new String[]{"bend", str(frequency), str(widt) + hkqo}; | |||
} | |||
} |
@@ -1,12 +1,23 @@ | |||
/* todo: | |||
- implement all sox effects | |||
- don't rerender on change of blend-mode | |||
- add blending option everywhere | |||
- add blend-effect to blend a selected layer | |||
- add png corruption | |||
- add png, jpg, gif and fractal compression artifact effects | |||
*/ | |||
import drop.*; | |||
import controlP5.*; | |||
import java.util.*; | |||
import processing.net.*; | |||
//import processing.net.*; | |||
import java.awt.event.KeyEvent; | |||
import java.awt.event.KeyListener; | |||
import processing.video.*; | |||
import com.hamoid.*; | |||
import java.io.*; | |||
import java.util.Arrays; | |||
Class<?> sketchClass; | |||
VideoExport videoExport; | |||
@@ -161,29 +172,55 @@ String getOS() { | |||
return "other"; | |||
} | |||
} | |||
/* | |||
boolean runCommand(String[] command) { | |||
//String returnedValues; | |||
//String returnedValues; | |||
try { | |||
Process p = new ProcessBuilder(command).start(); | |||
int ii = p.waitFor(); | |||
if (ii == 0) { //success signal | |||
//BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); | |||
//while ( (returnedValues = stdInput.readLine ()) != null) { | |||
//println(returnedValues); | |||
//} | |||
return(true); | |||
} else { | |||
//BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); | |||
//println("Error:"); | |||
//while ( (returnedValues = stdErr.readLine ()) != null) { | |||
//println(returnedValues); | |||
//} | |||
return(false); | |||
} | |||
} | |||
catch (Exception e) { | |||
//println("Error running command"); | |||
//println(e); | |||
return(false); | |||
} | |||
}*/ | |||
int runCommand(String[] command) { | |||
String returnedValues; | |||
try { | |||
println(command); | |||
Process p = new ProcessBuilder(command).start(); | |||
int ii = p.waitFor(); | |||
if (ii == 0) { //success signal | |||
//BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); | |||
//while ( (returnedValues = stdInput.readLine ()) != null) { | |||
//println(returnedValues); | |||
//} | |||
return(true); | |||
} else { | |||
//BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); | |||
//println("Error:"); | |||
//while ( (returnedValues = stdErr.readLine ()) != null) { | |||
//println(returnedValues); | |||
//} | |||
return(false); | |||
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); | |||
BufferedReader stdErr = new BufferedReader(new InputStreamReader(p.getErrorStream())); | |||
while ( (returnedValues = stdInput.readLine ()) != null) { | |||
println(returnedValues); | |||
} | |||
while ( (returnedValues = stdErr.readLine ()) != null) { | |||
println(returnedValues); | |||
} | |||
println(ii); | |||
return(ii); | |||
} | |||
catch (Exception e) { | |||
//println("Error running command"); | |||
//println(e); | |||
return(false); | |||
println("Error running command"); | |||
println(command); | |||
println(e); | |||
return(3); //error signal | |||
} | |||
} |
@@ -31,7 +31,71 @@ String FX[] = { | |||
"SEGMENTER", | |||
"COLORCRUSHER", | |||
"JPGCORRUPTION", | |||
"WEBPCORRUPTION" | |||
"WEBPCORRUPTION", | |||
"SOXALLPASS", | |||
"SOXBAND", | |||
"SOXBANDPASS", | |||
"SOXBANDREJECT", | |||
"SOXBASS", | |||
"SOXBEND", | |||
"SOXBIQUAD", | |||
"SOXCHORUS", | |||
"SOXCHANNELS", | |||
"SOXCOMPAND", | |||
"SOXCONTRAST", | |||
"SOXDCSHIFT", | |||
"SOXDEEMPH", | |||
"SOXDELAY", | |||
"SOXDITHER", | |||
"SOXDIVIDE", | |||
"SOXDOWNSAMPLE", | |||
"SOXEARWAX", | |||
"SOXECHO", | |||
"SOXECHOS", | |||
"SOXEQUALIZER", | |||
"SOXFADE", | |||
"SOXFIR", | |||
"SOXFIRFIT", | |||
"SOXFLANGER", | |||
"SOXGAIN", | |||
"SOXHIGHPASS", | |||
"SOXHILBERT", | |||
"SOXINPUT", | |||
"SOXLOUDNESS", | |||
"SOXLOWPASS", | |||
"SOXMCOMPAND", | |||
"SOXNOISEPROF", | |||
"SOXNOISERED", | |||
"SOXNORM", | |||
"SOXOOPS", | |||
"SOXOUTPUT", | |||
"SOXOVERDRIVE", | |||
"SOXPAD", | |||
"SOXPHASER", | |||
"SOXPITCH", | |||
"SOXRATE", | |||
"SOXREMIX", | |||
"SOXREPEAT", | |||
"SOXREVERB", | |||
"SOXREVERSE", | |||
"SOXRIAA", | |||
"SOXSILENCE", | |||
"SOXSINC", | |||
"SOXSPECTOGRAM", | |||
"SOXSPEED", | |||
"SOXSPLICE", | |||
"SOXSTAT", | |||
"SOXSTATS", | |||
"SOXSTRETCH", | |||
"SOXSWAP", | |||
"SOXSYNTH", | |||
"SOXTEMPO", | |||
"SOXTREBLE", | |||
"SOXTREMOLO", | |||
"SOXTRIM", | |||
"SOXUPSAMPLE", | |||
"SOXVAD", | |||
"SOXVOL" | |||
}; | |||