lang: add hack while AutoHashMap is broken
- image: add timer for runPlugin
This commit is contained in:
parent
fc3972d65c
commit
981b52c05b
2 changed files with 69 additions and 4 deletions
|
@ -243,6 +243,8 @@ pub const Image = struct {
|
||||||
position: plugins.Position,
|
position: plugins.Position,
|
||||||
params: plugins.ParamList,
|
params: plugins.ParamList,
|
||||||
) !void {
|
) !void {
|
||||||
|
var timer = try std.time.Timer.start();
|
||||||
|
|
||||||
var ctx = try plugins.makeContext(self.allocator, plugin_uri);
|
var ctx = try plugins.makeContext(self.allocator, plugin_uri);
|
||||||
defer ctx.deinit();
|
defer ctx.deinit();
|
||||||
|
|
||||||
|
@ -350,6 +352,9 @@ pub const Image = struct {
|
||||||
_ = c.sf_close(self.sndfile);
|
_ = c.sf_close(self.sndfile);
|
||||||
|
|
||||||
try self.reopen(tmpnam);
|
try self.reopen(tmpnam);
|
||||||
|
|
||||||
|
var time_taken = timer.read();
|
||||||
|
std.debug.warn("\ttook {d:.2}ms running plugin\n", time_taken * std.time.millisecond);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn saveTo(self: *Image, out_path: []const u8) !void {
|
pub fn saveTo(self: *Image, out_path: []const u8) !void {
|
||||||
|
|
68
src/lang.zig
68
src/lang.zig
|
@ -169,6 +169,66 @@ pub const Lang = struct {
|
||||||
_ = try self.keywords.put("rotate", .Rotate);
|
_ = try self.keywords.put("rotate", .Rotate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO remove this once AutoHashMap is fixed.
|
||||||
|
pub fn getCommand(self: *Lang, stmt: []const u8) ?CommandType {
|
||||||
|
const commands = [_][]const u8{
|
||||||
|
"noop",
|
||||||
|
"load",
|
||||||
|
"quicksave",
|
||||||
|
"runqs",
|
||||||
|
"amp",
|
||||||
|
"rflanger",
|
||||||
|
"eq",
|
||||||
|
"phaser",
|
||||||
|
"mbeq",
|
||||||
|
"chorus",
|
||||||
|
"pitchscaler",
|
||||||
|
"reverb",
|
||||||
|
"highpass",
|
||||||
|
"delay",
|
||||||
|
"vinyl",
|
||||||
|
"revdelay",
|
||||||
|
"noise",
|
||||||
|
"wildnoise",
|
||||||
|
"write",
|
||||||
|
"rotate",
|
||||||
|
};
|
||||||
|
|
||||||
|
const command_types = [_]CommandType{
|
||||||
|
.Noop,
|
||||||
|
.Load,
|
||||||
|
.Quicksave,
|
||||||
|
.RunQS,
|
||||||
|
|
||||||
|
.Amp,
|
||||||
|
.RFlanger,
|
||||||
|
.Eq,
|
||||||
|
.Phaser,
|
||||||
|
.Mbeq,
|
||||||
|
.Chorus,
|
||||||
|
.PitchScaler,
|
||||||
|
.Reverb,
|
||||||
|
.Highpass,
|
||||||
|
.Delay,
|
||||||
|
.Vinyl,
|
||||||
|
.RevDelay,
|
||||||
|
|
||||||
|
.Noise,
|
||||||
|
.WildNoise,
|
||||||
|
.Write,
|
||||||
|
|
||||||
|
.Rotate,
|
||||||
|
};
|
||||||
|
|
||||||
|
std.debug.assert(commands.len == command_types.len);
|
||||||
|
|
||||||
|
for (commands) |command, idx| {
|
||||||
|
if (std.mem.eql(u8, stmt, command)) return command_types[idx];
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse(self: *Lang, data: []const u8) !CommandList {
|
pub fn parse(self: *Lang, data: []const u8) !CommandList {
|
||||||
var splitted_it = std.mem.separate(data, ";");
|
var splitted_it = std.mem.separate(data, ";");
|
||||||
try self.fillKeywords();
|
try self.fillKeywords();
|
||||||
|
@ -188,12 +248,12 @@ pub const Lang = struct {
|
||||||
if (cmd_opt == null) return ParseError.NoCommandGiven;
|
if (cmd_opt == null) return ParseError.NoCommandGiven;
|
||||||
var command = cmd_opt.?;
|
var command = cmd_opt.?;
|
||||||
|
|
||||||
var kv_opt = self.keywords.get(command);
|
var ctype_opt = self.getCommand(command);
|
||||||
var ctype: CommandType = undefined;
|
var ctype: CommandType = undefined;
|
||||||
if (kv_opt) |kv| {
|
if (ctype_opt) |ctype_val| {
|
||||||
ctype = kv.value;
|
ctype = ctype_val;
|
||||||
} else {
|
} else {
|
||||||
std.debug.warn("Unknown command: '{}'\n", command);
|
std.debug.warn("Unknown command: '{}' ({})\n", command, command.len);
|
||||||
return ParseError.UnknownCommand;
|
return ParseError.UnknownCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue