add setting of parameters to the ports
- fix ampCmd's param pass
This commit is contained in:
		
							parent
							
								
									bbf34f1133
								
							
						
					
					
						commit
						05fe41d8b4
					
				
					 3 changed files with 38 additions and 17 deletions
				
			
		|  | @ -1,12 +1,6 @@ | ||||||
| const std = @import("std"); | const std = @import("std"); | ||||||
| const lv2 = @import("lv2_helpers.zig"); | const lv2 = @import("lv2_helpers.zig"); | ||||||
| 
 | const c = lv2.c; | ||||||
| const c = @cImport({ |  | ||||||
|     @cInclude("sndfile.h"); |  | ||||||
| 
 |  | ||||||
|     @cInclude("lilv/lilv.h"); |  | ||||||
|     @cInclude("lv2/core/lv2.h"); |  | ||||||
| }); |  | ||||||
| 
 | 
 | ||||||
| const plugins = @import("plugin.zig"); | const plugins = @import("plugin.zig"); | ||||||
| 
 | 
 | ||||||
|  | @ -14,6 +8,7 @@ pub const ImageError = error{ | ||||||
|     OpenFail, |     OpenFail, | ||||||
|     InvalidPlugin, |     InvalidPlugin, | ||||||
|     UnknownPlugin, |     UnknownPlugin, | ||||||
|  |     InvalidSymbol, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| /// Low level integration function with libsndfile. | /// Low level integration function with libsndfile. | ||||||
|  | @ -103,13 +98,41 @@ pub const Image = struct { | ||||||
|         pos: plugins.Position, |         pos: plugins.Position, | ||||||
|         params: plugins.ParamList, |         params: plugins.ParamList, | ||||||
|     ) !void { |     ) !void { | ||||||
|         var context = try plugins.makeContext(self.allocator, plugin_uri); |         var ctx = try plugins.makeContext(self.allocator, plugin_uri); | ||||||
|         std.debug.warn("world: {}\n", context.world); |         std.debug.warn("\tworld: {}\n", ctx.world); | ||||||
|         std.debug.warn("plugin: {}\n", context.plugin); |         std.debug.warn("\tplugin: {}\n", ctx.plugin); | ||||||
| 
 | 
 | ||||||
|         var ports = try lv2.setupPorts(&context); |         var ports = try lv2.setupPorts(&ctx); | ||||||
|         for (ports) |port| { | 
 | ||||||
|             std.debug.warn("port: {}\n", port.*); |         if (ctx.n_audio_in != 1) { | ||||||
|  |             std.debug.warn("plugin <{}> does not accept mono input.\n", plugin_uri); | ||||||
|  |             return ImageError.InvalidPlugin; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         // now, for each param for the plugin, we find its port, and set | ||||||
|  |         // the value for the port there. | ||||||
|  |         var it = params.iterator(); | ||||||
|  | 
 | ||||||
|  |         while (it.next()) |param| { | ||||||
|  |             var sym_cstr = try std.cstr.addNullByte(self.allocator, param.sym); | ||||||
|  |             defer self.allocator.free(sym_cstr); | ||||||
|  | 
 | ||||||
|  |             var sym = c.lilv_new_string(ctx.world, sym_cstr.ptr); | ||||||
|  |             const port = c.lilv_plugin_get_port_by_symbol(ctx.plugin, sym) orelse blk: { | ||||||
|  |                 std.debug.warn("assert fail: symbol not found on port"); | ||||||
|  |                 return ImageError.InvalidSymbol; | ||||||
|  |             }; | ||||||
|  | 
 | ||||||
|  |             c.lilv_node_free(sym); | ||||||
|  | 
 | ||||||
|  |             var idx = c.lilv_port_get_index(ctx.plugin, port); | ||||||
|  |             std.debug.warn( | ||||||
|  |                 "sym={}, idx={} to val={}\n", | ||||||
|  |                 param.sym, | ||||||
|  |                 idx, | ||||||
|  |                 param.value, | ||||||
|  |             ); | ||||||
|  |             ports[idx].value = param.value; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -2,6 +2,7 @@ const std = @import("std"); | ||||||
| const plugin = @import("plugin.zig"); | const plugin = @import("plugin.zig"); | ||||||
| 
 | 
 | ||||||
| pub const c = @cImport({ | pub const c = @cImport({ | ||||||
|  |     @cInclude("sndfile.h"); | ||||||
|     @cInclude("lilv/lilv.h"); |     @cInclude("lilv/lilv.h"); | ||||||
|     @cInclude("lv2/core/lv2.h"); |     @cInclude("lv2/core/lv2.h"); | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | @ -143,12 +143,9 @@ pub const Runner = struct { | ||||||
|     /// Run the http://lv2plug.in/plugins/eg-amp plugin over the file. |     /// Run the http://lv2plug.in/plugins/eg-amp plugin over the file. | ||||||
|     fn ampCmd(self: *Runner, split: usize, index: usize, gain: f32) !void { |     fn ampCmd(self: *Runner, split: usize, index: usize, gain: f32) !void { | ||||||
|         var image = try self.getImage(); |         var image = try self.getImage(); | ||||||
|         var param = try self.allocator.create(plugin.Param); |  | ||||||
|         defer self.allocator.destroy(param); |  | ||||||
| 
 |  | ||||||
|         param.* = plugin.Param{ .sym = "gain", .value = gain }; |  | ||||||
| 
 | 
 | ||||||
|         var params = plugin.ParamList.init(self.allocator); |         var params = plugin.ParamList.init(self.allocator); | ||||||
|  |         try params.append(plugin.Param{ .sym = "gain", .value = gain }); | ||||||
|         defer params.deinit(); |         defer params.deinit(); | ||||||
| 
 | 
 | ||||||
|         try image.runPlugin( |         try image.runPlugin( | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue