This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
ThinkInvisible's profile picture

[MiscPeripherals] ModTrack - Music Creator

Started by ThinkInvisible, 02 April 2013 - 02:00 AM
ThinkInvisible #1
Posted 02 April 2013 - 04:00 AM
( This uses the MiscPeripherals mod to work, get it here: http://www.computerc...peripherals-31/ )

A program designed to create note block music in-game.
To use it, you must place an Iron Note Block to the LEFT of the computer.
As colors and clicking are used, you will need an Advanced Computer to
run this program. It has not been tested using a Monitor, and most functions
will probably be broken if you use the Monitor program with this.

Code:
http://pastebin.com/ch10vaXu

An example song file:
http://dl.dropbox.co...11769/ex_piano1
(Pastebin thinks it's too big! Sorry.)

A tracker is a music editing program that uses a grid of cells. Each
cell contains a note and an instrument - for example,
Piano C# (Octave 4). In ModTrack, this is displayed as
C#
P4

and a blank note will simply be four dashes.




The keys to press to insert notes (C#4 means 'C# Octave 4'):



(The help screen and a simple major-minor scale.)


Known bugs:
-No safeguards for bad file names while saving/loading.
-Playing stops when the song is saved or loaded
Double-click Play to fix this!
-Middle-clicking is not implemented yet!
Left4Cake #2
Posted 02 April 2013 - 04:45 AM
It would be awesome if you made a version compatible with my iron note block player. I would try something like this but I am working on c++ right now.
ThinkInvisible #3
Posted 02 April 2013 - 04:52 AM
It would be awesome if you made a version compatible with my iron note block player. I would try something like this but I am working on c++ right now.
What exactly do you mean by 'compatible'?
ThinkInvisible #4
Posted 02 April 2013 - 07:40 AM
Updated with a small change to module saving/loading - apparently, using an array as a variable links it to the new variable.

Whoops! Still doing things with zero-based numbers. Fixed again.
theoriginalbit #5
Posted 02 April 2013 - 07:44 AM
Updated with a small change to module saving/loading - apparently, using an array as a variable links it to the new variable.
This is because tables are stored by reference, not value. so when you have

table1 = {}
table2 = table1
they both point to the same location in memory… so if you modify table1, table2 will also have the change, same for the other way around
Left4Cake #6
Posted 02 April 2013 - 08:59 AM
It would be awesome if you made a version compatible with my iron note block player. I would try something like this but I am working on c++ right now.
What exactly do you mean by 'compatible'?

To be able to make songs in this that can be played in my player. The main difference between the formats is that you save each value on a new line and MysticT's save it as an arrays in a file.
ThinkInvisible #7
Posted 02 April 2013 - 10:31 AM
Okay, I'm bad with tables. This is what I have so far; for some reason it isn't saving any of the notes, only the title and such. Anyone see the problem?
function APIExport_MysticT(fname)
f = fs.open(fname, "w")
t = {}
t.delay = 4/tempo
t.title = fname
t.author = "ModTrack"
for i = modStart, modEnd do
for j = 1, 32 do
ntemp = i * 32 + j
nt1 = extModulesNote[i][1][k]
nt2 = extModulesNote[i][2][k]
nt3 = extModulesNote[i][3][k]
nt4 = extModulesNote[i][4][k]
it1 = extModulesInst[i][1][k]
it2 = extModulesInst[i][2][k]
it3 = extModulesInst[i][3][k]
it4 = extModulesInst[i][4][k]
in1 = {}
in2 = {}
in3 = {}
in4 = {}
in5 = {}
if(it1 == 0) then table.insert(in1, nt1) end
if(it1 == 1) then table.insert(in2, nt1) end
if(it1 == 2) then table.insert(in3, nt1) end
if(it1 == 3) then table.insert(in4, nt1) end
if(it1 == 4) then table.insert(in5, nt1) end
if(it2 == 0) then table.insert(in1, nt2) end
if(it2 == 1) then table.insert(in2, nt2) end
if(it2 == 2) then table.insert(in3, nt2) end
if(it2 == 3) then table.insert(in4, nt2) end
if(it2 == 4) then table.insert(in5, nt2) end
if(it3 == 0) then table.insert(in1, nt3) end
if(it3 == 1) then table.insert(in2, nt3) end
if(it3 == 2) then table.insert(in3, nt3) end
if(it3 == 3) then table.insert(in4, nt3) end
if(it3 == 4) then table.insert(in5, nt3) end
if(it4 == 0) then table.insert(in1, nt4) end
if(it4 == 1) then table.insert(in2, nt4) end
if(it4 == 2) then table.insert(in3, nt4) end
if(it4 == 3) then table.insert(in4, nt4) end
if(it4 == 4) then table.insert(in5, nt4) end
for k = 1, #in1 do
t[ntemp].i1.i = in1[k]
end
for k = 1, #in2 do
t[ntemp].i2.i = in2[k]
end
for k = 1, #in3 do
t[ntemp].i3.i = in3[k]
end
for k = 1, #in4 do
t[ntemp].i4.i = in4[k]
end
for k = 1, #in5 do
t[ntemp].i5.i = in5[k]
end
end
end
f.writeLine(textutils.serialize(t))
f.close()
end