Compare commits
No commits in common. "8c2bbee372c5ae33716ea728ba65d0d2cb04a361" and "2bf44bc5818ec49b644ce77a569d4dbe291aee01" have entirely different histories.
8c2bbee372
...
2bf44bc581
2 changed files with 34 additions and 25 deletions
|
@ -1,3 +1,8 @@
|
||||||
load :0;
|
load :0;
|
||||||
amp 3 1 10;
|
amp 80 70 10;
|
||||||
|
amp 80 73 20;
|
||||||
|
amp 80 75 20;
|
||||||
|
amp 80 76 20;
|
||||||
|
amp 7 4 2;
|
||||||
|
amp 5 1 8;
|
||||||
quicksave;
|
quicksave;
|
||||||
|
|
|
@ -54,6 +54,12 @@ fn swrite(file: *c.SNDFILE, buf: [*]f32, frames: i64) !void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn getEndPos(path: []const u8) !usize {
|
||||||
|
var file = try std.fs.File.openRead(path);
|
||||||
|
defer file.close();
|
||||||
|
return file.getEndPos();
|
||||||
|
}
|
||||||
|
|
||||||
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
||||||
const template_start = "/temp/temp_";
|
const template_start = "/temp/temp_";
|
||||||
const template = "/tmp/temp_XXXXXXXX";
|
const template = "/tmp/temp_XXXXXXXX";
|
||||||
|
@ -102,31 +108,24 @@ pub const Image = struct {
|
||||||
/// Pointer to the underlying libsndfile's SNDFILE struct.
|
/// Pointer to the underlying libsndfile's SNDFILE struct.
|
||||||
sndfile: *c.SNDFILE,
|
sndfile: *c.SNDFILE,
|
||||||
|
|
||||||
/// Current sound file's framecount.
|
|
||||||
frames: usize,
|
|
||||||
|
|
||||||
/// The original image file path.
|
/// The original image file path.
|
||||||
path: []const u8,
|
path: []const u8,
|
||||||
|
|
||||||
/// Represents the current path being worked on.
|
/// Represents the current path being worked on.
|
||||||
curpath: []const u8,
|
curpath: []const u8,
|
||||||
|
|
||||||
/// Open a BMP image for later.
|
/// Open a BMP file.
|
||||||
pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image {
|
pub fn open(allocator: *std.mem.Allocator, path: []const u8) !*Image {
|
||||||
var in_fmt = mkSfInfo();
|
var in_fmt = mkSfInfo();
|
||||||
|
|
||||||
var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt);
|
var sndfile = try sopen(allocator, path, c.SFM_READ, &in_fmt);
|
||||||
var image = try allocator.create(Image);
|
var image = try allocator.create(Image);
|
||||||
|
|
||||||
std.debug.assert(in_fmt.frames > i64(0));
|
|
||||||
std.debug.assert(in_fmt.seekable == i32(1));
|
|
||||||
|
|
||||||
image.* = Image{
|
image.* = Image{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.sndfile = sndfile,
|
.sndfile = sndfile,
|
||||||
.path = path,
|
.path = path,
|
||||||
.curpath = path,
|
.curpath = path,
|
||||||
.frames = @intCast(usize, in_fmt.frames),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return image;
|
return image;
|
||||||
|
@ -162,12 +161,10 @@ pub const Image = struct {
|
||||||
fn copyBytes(
|
fn copyBytes(
|
||||||
self: *Image,
|
self: *Image,
|
||||||
out_file: *c.SNDFILE,
|
out_file: *c.SNDFILE,
|
||||||
|
buf: []f32,
|
||||||
start: usize,
|
start: usize,
|
||||||
end: usize,
|
end: usize,
|
||||||
) !void {
|
) !void {
|
||||||
var buf = try self.allocator.alloc(f32, BufferSize);
|
|
||||||
defer self.allocator.free(buf);
|
|
||||||
|
|
||||||
const total_bytes = end - start;
|
const total_bytes = end - start;
|
||||||
var i: usize = start;
|
var i: usize = start;
|
||||||
|
|
||||||
|
@ -200,13 +197,6 @@ pub const Image = struct {
|
||||||
_ = c.sf_seek(self.sndfile, @intCast(i64, end), c.SEEK_SET);
|
_ = c.sf_seek(self.sndfile, @intCast(i64, end), c.SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn getSeekPos(self: *Image, position: plugins.Position) plugins.SeekPos {
|
|
||||||
const file_end = self.frames;
|
|
||||||
var seek_pos = position.seekPos(file_end);
|
|
||||||
std.debug.warn("\tstart {} end {}\n", seek_pos.start, seek_pos.end);
|
|
||||||
return seek_pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Run a plugin over the image.
|
/// Run a plugin over the image.
|
||||||
/// This setups a new lilv world/plugin among other things.
|
/// This setups a new lilv world/plugin among other things.
|
||||||
/// The internal SNDFILE pointer is modified to point to the output of the
|
/// The internal SNDFILE pointer is modified to point to the output of the
|
||||||
|
@ -273,7 +263,9 @@ pub const Image = struct {
|
||||||
// just copy the original image and the part where we run the plugin
|
// just copy the original image and the part where we run the plugin
|
||||||
// over the image.
|
// over the image.
|
||||||
|
|
||||||
const seek_pos = self.getSeekPos(position);
|
const file_end = try getEndPos(self.curpath);
|
||||||
|
const seek_pos = position.seekPos(file_end);
|
||||||
|
std.debug.warn("\tstart {} end {}\n", seek_pos.start, seek_pos.end);
|
||||||
|
|
||||||
// make sure we start from 0
|
// make sure we start from 0
|
||||||
_ = c.sf_seek(self.sndfile, 0, c.SEEK_SET);
|
_ = c.sf_seek(self.sndfile, 0, c.SEEK_SET);
|
||||||
|
@ -284,11 +276,15 @@ pub const Image = struct {
|
||||||
// - plugin
|
// - plugin
|
||||||
// - post-plugin
|
// - post-plugin
|
||||||
|
|
||||||
|
var file_copy_buf = try self.allocator.alloc(f32, BufferSize);
|
||||||
|
defer self.allocator.free(file_copy_buf);
|
||||||
|
|
||||||
// pre-plugin copy, merged with bmp header copy
|
// pre-plugin copy, merged with bmp header copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
|
file_copy_buf,
|
||||||
usize(0),
|
usize(0),
|
||||||
seek_pos.start,
|
seek_pos.start + @mod(seek_pos.start, BufferSize),
|
||||||
);
|
);
|
||||||
|
|
||||||
_ = c.sf_seek(self.sndfile, @intCast(i64, seek_pos.start), c.SEEK_SET);
|
_ = c.sf_seek(self.sndfile, @intCast(i64, seek_pos.start), c.SEEK_SET);
|
||||||
|
@ -315,8 +311,9 @@ pub const Image = struct {
|
||||||
// post-plugin copy
|
// post-plugin copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
|
file_copy_buf,
|
||||||
seek_pos.end + 1,
|
seek_pos.end + 1,
|
||||||
self.frames,
|
file_end + @mod(file_end, BufferSize),
|
||||||
);
|
);
|
||||||
|
|
||||||
c.sf_write_sync(out_file);
|
c.sf_write_sync(out_file);
|
||||||
|
@ -352,7 +349,9 @@ pub const Image = struct {
|
||||||
var bufs = try plugins.RunBuffers.init(self.allocator);
|
var bufs = try plugins.RunBuffers.init(self.allocator);
|
||||||
defer bufs.deinit();
|
defer bufs.deinit();
|
||||||
|
|
||||||
const seek_pos = self.getSeekPos(position);
|
const file_end = try getEndPos(self.curpath);
|
||||||
|
const seek_pos = position.seekPos(file_end);
|
||||||
|
std.debug.warn("\tstart {} end {}\n", seek_pos.start, seek_pos.end);
|
||||||
|
|
||||||
// make sure we start from 0
|
// make sure we start from 0
|
||||||
_ = c.sf_seek(self.sndfile, 0, c.SEEK_SET);
|
_ = c.sf_seek(self.sndfile, 0, c.SEEK_SET);
|
||||||
|
@ -363,11 +362,15 @@ pub const Image = struct {
|
||||||
// - CUSTOM plugin
|
// - CUSTOM plugin
|
||||||
// - post-plugin
|
// - post-plugin
|
||||||
|
|
||||||
|
var file_copy_buf = try self.allocator.alloc(f32, BufferSize);
|
||||||
|
defer self.allocator.free(file_copy_buf);
|
||||||
|
|
||||||
// pre-plugin copy, merged with bmp header copy
|
// pre-plugin copy, merged with bmp header copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
|
file_copy_buf,
|
||||||
usize(0),
|
usize(0),
|
||||||
seek_pos.start,
|
seek_pos.start + @mod(seek_pos.start, BufferSize),
|
||||||
);
|
);
|
||||||
|
|
||||||
_ = c.sf_seek(self.sndfile, @intCast(i64, seek_pos.start), c.SEEK_SET);
|
_ = c.sf_seek(self.sndfile, @intCast(i64, seek_pos.start), c.SEEK_SET);
|
||||||
|
@ -394,8 +397,9 @@ pub const Image = struct {
|
||||||
// post-plugin copy
|
// post-plugin copy
|
||||||
try self.copyBytes(
|
try self.copyBytes(
|
||||||
out_file,
|
out_file,
|
||||||
|
file_copy_buf,
|
||||||
seek_pos.end + 1,
|
seek_pos.end + 1,
|
||||||
self.frames,
|
file_end + @mod(file_end, BufferSize),
|
||||||
);
|
);
|
||||||
|
|
||||||
c.sf_write_sync(out_file);
|
c.sf_write_sync(out_file);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue