Love music but not too good with code...
#1
Posted 02 June 2012 - 03:49 AM
#2
Posted 02 June 2012 - 04:01 AM
Then use redstone.setBundledOutput to activate different note blocks.
You could even connect one color to multiple note blocks, so that activating a color would play a chord.
#3
Posted 02 June 2012 - 07:14 PM
rs.setBundledOutput("back", colors.white+colors.red)
os.sleep(0.2)
rs.setBundledOutput("back", 0)
os.sleep(0.2)
rs.setBundledOutput("back", colors.red+colors.blue+colors.green)
os.sleep(0.2)
rs.setBundledOutput("back", 0)
os.sleep(0.2)
Of course, this is dependent on having red power wiring installed. If you do not, you are going to have to create a binary selector using different directions of redstone cabling, which requires some serious work.
Edited for correctness.
#4
Posted 02 June 2012 - 07:32 PM
Can I combine a color from the left and right side?
#5
Posted 03 June 2012 - 07:34 AM
#6
Posted 07 June 2012 - 03:05 AM
#7
Posted 07 June 2012 - 05:59 PM
rs.setBundledOutput("back", colors.white+colors.red)
This is the command to set the output in a specific direction. "rs.setBundledOutput" is the name of the function, and what is between the brackets ( ) is the parameters, which determines what it does.The "back" part (before the first comma) is the DIRECTION you want the computer to set output in. You only can control one direction at a time. For example, if I want to output to the left, I put in "left", right is "right", and same for down and up. When this command runs, the output signal in that direction will be the same until you call a different command, so you can do left and then right, and they will both turn on essentially instantly until you turn them off.
The colors.white+colors.red determines which colored outputs should be set to on. All the other ones on that side will be set to off. So, if you want to play 2 notes on the left, and 2 on the right, at the same time, you would go
rs.setBundledOutput("left", colors.white+colors.red)
rs.setBundledOutput("right", colors.red)
If you wish to turn off all the notes, instead of putting in a color, you type in 0 instead of numbers.Now you cant just turn a wire on and off right after each other, or it wont work. You have to wait between commands for at least the length of a tick (which can vary). In this case, you can use the sleep command and wait for that amount of time in seconds before doing the next command.
Finally, if you do this
rs.setBundledOutput("back", colors.green)
os.sleep(1.5)
rs.setBundledOutput("back", colors.green)
it the note will have been on the whole time. You should shut them off between notes.I hope that is comprehensive enough, I dont know if I can explain it any more simply.
#8
Posted 07 June 2012 - 08:56 PM
#9
Posted 08 June 2012 - 01:01 AM
#10
Posted 23 June 2012 - 09:29 PM
Bossman201, on 08 June 2012 - 01:01 AM, said:
Care to explain? If there is a better or simpler way to im all ears
#11
Posted 23 June 2012 - 10:44 PM
Huufalem, on 23 June 2012 - 09:29 PM, said:
Bossman201, on 08 June 2012 - 01:01 AM, said:
Care to explain? If there is a better or simpler way to im all ears
Imagine you have a number of computers. Some are "clients" and one is the "server". They are all hooked up to wireless routers. You can have all listening for messages from the server, and if the message they receive is for one of the notes they are connected to, they play it. So, a program like this:
rednet.open("top")
while true do
senderID, message, distance = rednet.receive()
if message == "on 1" then
rs.setOutput("back", true)
elseif message == "off 1" then
rs.setOutput("back", false)
elseif message == "on 2" then
rs.setOutput("left", true)
elseif message == "off 2 then
rs.setOutput("left", false)
end
end
In the above case, the computer has a wireless router on top of it, and a note block behind it and a different one to the left.Now, you can have the server, or you can think of it as the conductor, broadcast messages, and the other computer will obey, as long as they are within wireless range.
-- assuming the router is on top, connect to it
rednet.open("top")
-- first, start by turning on power to a single note block
rednet.broadcast("on 1")
-- wait half a second
sleep(0.5)
-- now turn power off
rednet.broadcast("off 1")
-- and start playing another not at the same time
rednet.broadcast("on 2")
-- wait a little while for it to play
sleep(0.5)
-- and shut it off, and wait a while again
rednet.broadcast("off 2")
-- we can also play notes on other computers (assuming they are set up properly)
-- you can also play multiple at the same time
rednet.broadcast("on 3")
rednet.broadcast("on 5")
sleep(0.5)
rednet.broadcast("off 3")
rednet.broadcast("off 5")
This might not be the most efficient way of doing this or whatever, but it should be easy enough to get you started. Maybe I will cook something up tonight. If you have ever worked with midi, it is somewhat similar to that.
#12
Posted 24 June 2012 - 04:55 AM
rednet.open("top")
while true do
senderID, message, distance = rednet.receive()
if message == "on 1" then
rs.setBundledOutput(("back"), colors.red)
That could be wrong but that is what I am guessing it should look like. But I still fail to understand how I would get different clients. Would I just place the modem on a different side of the computer?
#13
Posted 24 June 2012 - 01:50 PM
Huufalem, on 24 June 2012 - 04:55 AM, said:
rednet.open("top")
while true do
senderID, message, distance = rednet.receive()
if message == "on 1" then
rs.setBundledOutput(("back"), colors.red)
That could be wrong but that is what I am guessing it should look like. But I still fail to understand how I would get different clients. Would I just place the modem on a different side of the computer?
Close. First of all, some small syntax mistakes: whenever you indent, you need to end the block afterwards like this:
rednet.open("top")
while true do
senderID, message, distance = rednet.receive()
if message == "on 1" then
rs.setBundledOutput("back", colors.red)
end
end
Next, for the communication, I was using "rednet.broadcast(message)". This sends the same message to every single computer nearby. So, if you have 4 computers, ALL of them will get it. However, only one of the computers will have (if message == "on 1"), and so only one will do anything. The rest will get the message, see if it matches any of their if-statements (which it won't, because you will have set it to listen for different messages, like (if message == "on 6")), and then end up not doing anything.
The different sides for the note blocks are just so you can fit up to 4 note blocks per computer WITHOUT using redpower wire (because one side has to have the wireless and you cant attach to the front afaik). If you use the bundled cables, then you can get 16*5=80 notes on one computer, and two of which can play simultaneously, but with the disadvantage that controlling them is a little bit more confusing, because it involves flag-setting and binary. Plus, computercraft materials is actually really cheap, and you don't have to run wires everywhere. That is what bossman was saying. If you really want to use redpower, however, this was already covered at some length earlier in the thread, and the documentation might help too.
#14
Posted 24 June 2012 - 04:03 PM
Huufalem, on 02 June 2012 - 03:49 AM, said:
The wiki will be your friend for eternity...
#15
Posted 24 June 2012 - 05:59 PM
115/4=29 computers (Clients)
+ 1 computer (server)
And in order to set up the computers Say computer one plays notes 1-4 so it would be on 1 back on 2 left on 3 right on 4 front. Then computer two would be on 5 back on 6 left on 7 right on 8 front? Is this correct?
#16
Posted 24 June 2012 - 06:18 PM
The setup is pretty easy, and I'm almost done with the programs.
kazagistar, on 24 June 2012 - 01:50 PM, said:
#17
Posted 24 June 2012 - 06:23 PM
MysticT, on 24 June 2012 - 06:18 PM, said:
The setup is pretty easy, and I'm almost done with the programs.
Ah okay, What do you mean your almost done with the programs? Are you releasing something easy to use
#18
Posted 24 June 2012 - 06:45 PM
Huufalem, on 24 June 2012 - 06:23 PM, said:
nb.play(1, 10) -- play E on bass guitar
nb.play(5, 5) -- play B on piano
nb.play(4, { 0, 1, 2, 3, 4, 5 }) -- play some notes on bass drum
nb.play({ [2] = 2, [3] = { 6, 7, 8 } }) -- play notes on some instruments ([instrument] = <notes>)
And maybe I'll add some functions to play songs or something. But first I have to make it work #19
Posted 24 June 2012 - 06:53 PM
MysticT, on 24 June 2012 - 06:45 PM, said:
Huufalem, on 24 June 2012 - 06:23 PM, said:
nb.play(1, 10) -- play E on bass guitar
nb.play(5, 5) -- play B on piano
nb.play(4, { 0, 1, 2, 3, 4, 5 }) -- play some notes on bass drum
nb.play({ [2] = 2, [3] = { 6, 7, 8 } }) -- play notes on some instruments ([instrument] = <notes>)
And maybe I'll add some functions to play songs or something. But first I have to make it work Or just release your code, and I will just mod it in.
#20
Posted 25 June 2012 - 12:28 AM
local note = "whatever note you want to play" --ex. E F G A B C D including sharps and flats
while true do
id, message = os.pullEvent("rednet_message")
if message == note then
--handle redstone turn-on state
--turn off redstone state
end
end
Make the clients turn off redstone themselves, no reason to add extra network overhead. Note: This loop will run forever, that was intended.As for the server, I would create a program that loads a table from a file into memory and then will broadcast each value in the table, using a timer to regulate your time BPM.
local iBPM = nil
if tSong[1] ~= "nil" then --Yes, this is a string because leaving a nil key in a table is poor programming etiquette, if you ask me.
iBPM = 60 / tSong[1]
else
print("Enter BPM: ")
iBPM = 60 / tonumber(io.read())
end
tTimer = os.startTimer(iBPM)
A value could be added in the beginning of the table(example above) to indicate the BPM(beats per minute) of a song. My example breaks down BPM into BPS as timers use seconds, not minutes; Which is how I'd keep track of BPM.Ideally you would want your timer to cycle at least 64(must be base 2, as that's how music works) times per measure, but that could cause too much overhead/exponential increases in memory required by the table as most entries will be 0 or "nil". Then I'd use a code like this to read/broadcast:
local terminate = false
local iBPM --previously declared, just here so you do not forget
local i = 3
local iEnd = tSong[2] --need some internal way to tell the end of the song, table length stored in entry 2. Just thought of a better way using #tSong but I'm not going to change the code a third time.
while terminate == false do
evt, p1 = os.pullEvent("timer")
if p1 == "tTimer" then
tTimer = os.startTimer(iBPM)
end
rednet.broadcast(tSong[i])
i = i + 1
if i == iEnd + 1 then
terminate = true
end
end
One problem with this is that your song can only play one note at a time so your solution is to use matrices or do some fancy parallel API shit. Which I don't know.
I planned to create a music editor, music player, and a turtle program to set up your player, based on what I've described above. But I couldn't find a good spot for it, so the project was scrapped (biggest reason why my projects fail is that they're never even started).
Sources: I know a bit about music too
EDIT: After editing for the 10999th time, and reformatting my code each time, I decided that someone needs to fix that about the forums. EDIT OF EDIT:
Since there are multiple instruments, it would be wise to add that into the entry before what actual note is played, here's an example table.
local tSong = {1 C, 2 E, 5 F, 2 G, 3 A, 4 B}
You won't have to change the client code that I posted in the beginning of the post, you must merely change the contents of variable 'note' to include which instrument it is.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











