Mod Archive Forums Mod Archive Forums
Advanced search  

News:

Please note: Your main modarchive.org account will not work here, you must create a forum account to post on the forums.

Pages: [1]   Go Down

Author Topic: random create "ins" lua script  (Read 2794 times)

0 Members and 2 Guests are viewing this topic.

clear2ooo

  • New User
  • Offline Offline
  • Posts: 13
    • View Profile
random create "ins" lua script
« on: April 28, 2024, 09:39:48 »

create "ins"

in a few days i will not have internet anymore.

although probably there are a few more of this kind of program. i provide here. to use how you want. a simple program which is a lua script. to create "ins" file for hivelytracker. it creates a silly sound from two to four steps in size. it is very limited. sometimes it creates sound effect, all keys give the same sound sequence. sometimes it create instrument which doesn't have sequence notes in key of "c". i did something because it kept giving me illegal waveform of "5" on first position. then try to play note and it crashes hivelytracker. so ensure waveform is "1", "2" or "4" for first position only.

this script create file called "createins.ins" in your user's "documents" directory. change it what makes you comfortable. path name assumes linux. but could be changed easily to save file in windows.

Code: [Select]
ran, floor = math.random, math.floor
insfile = {
84, 72, 88, 73, 32, 3, 1, 32, 32, 32, 128,
1, 0, 0, 0, 0, 1, 0, 0, 0, 32, 32, 0,
1, 2, 4, 128, 129, 0, 16, 160, 13, 0, 0, 0,
25, 0, 0, 0, 37, 0, 0, 49, 50, 51, 52, 53,
54, 55, 56, 0
}

binlift_pow2 = { 128, 64, 32, 16, 8, 4, 2, 1 }
function binlift(num, dolift)
    local i
    local iret = 0
    local s = { }
    for i = 1, 8 do
        if floor(num - binlift_pow2[i]) > 0 then
            s[i] = 1
            num = num - binlift_pow2[i]
        else
            s[i] = 0
        end
    end
    if dolift then s[2] = 1 else s[2] = 0 end
    for i = 1, 8 do
        if s[i] == 1 then iret = iret + binlift_pow2[i] end
    end
    return iret
end

numsteps = ran(2, 4)
if numsteps > 2 then
    insfile[31] = 0
    if numsteps == 3 then
        insfile[35] = 160 + ran(0, 2)
    else
        insfile[39] = 160 + ran(0, 2)
    end
end
seqspeed = ran(2, 6)
if seqspeed > 2 then
    insfile[25] = seqspeed
end
-- change "wavelen"
insfile[6] = ran(2, 4)
-- change note in "c" key
--   note: this doesn't always work
insfile[28] = ran(0, 3) * 12 + 129
insfile[32] = ran(0, 3) * 12 + 1
insfile[36] = ran(0, 3) * 12 + 1
insfile[40] = ran(0, 3) * 12 + 1
if ran(1, 2) == 1 then
    -- make all notes fixed!
    insfile[28] = binlift(insfile[28], true)
    insfile[32] = binlift(insfile[32], true)
    insfile[36] = binlift(insfile[36], true)
    insfile[40] = binlift(insfile[40], true)
end
-- change first sequence waveform
if ran(1, 3) == 1 then
    insfile[27] = 129
    if insfile[28] >= 128 then insfile[28] = insfile[28] - 128 end
elseif ran(1, 3) == 1 then
    insfile[27] = 130
    if insfile[28] >= 128 then insfile[28] = insfile[28] - 128 end
elseif ran(1, 3) == 1 then
    insfile[27] = 129
end
-- invent instrument name
for i = 0, 7 do
    insfile[0x2b + i] = ran(97, 122)
end
-- output file
outf = io.open(os.getenv("HOME") .. "/Documents/createins.ins", "wb")
if outf then
    for i = 1, #insfile do
        outf:write(string.char(insfile[i]))
    end
    outf:close()
end


this space is intentionally left blank.
Logged
Pages: [1]   Go Up