lang: add hack while AutoHashMap is broken

- image: add timer for runPlugin
This commit is contained in:
Luna 2019-08-06 23:34:11 -03:00
parent fc3972d65c
commit 981b52c05b
2 changed files with 69 additions and 4 deletions

View file

@ -243,6 +243,8 @@ pub const Image = struct {
position: plugins.Position,
params: plugins.ParamList,
) !void {
var timer = try std.time.Timer.start();
var ctx = try plugins.makeContext(self.allocator, plugin_uri);
defer ctx.deinit();
@ -350,6 +352,9 @@ pub const Image = struct {
_ = c.sf_close(self.sndfile);
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 {

View file

@ -169,6 +169,66 @@ pub const Lang = struct {
_ = 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 {
var splitted_it = std.mem.separate(data, ";");
try self.fillKeywords();
@ -188,12 +248,12 @@ pub const Lang = struct {
if (cmd_opt == null) return ParseError.NoCommandGiven;
var command = cmd_opt.?;
var kv_opt = self.keywords.get(command);
var ctype_opt = self.getCommand(command);
var ctype: CommandType = undefined;
if (kv_opt) |kv| {
ctype = kv.value;
if (ctype_opt) |ctype_val| {
ctype = ctype_val;
} else {
std.debug.warn("Unknown command: '{}'\n", command);
std.debug.warn("Unknown command: '{}' ({})\n", command, command.len);
return ParseError.UnknownCommand;
}