Jump to content




NoteBlock API & NoteBlock Player

api computer

  • You cannot reply to this topic
40 replies to this topic

#1 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 03 July 2012 - 05:58 PM

Ever wanted to make some music with noteblocks but you don't want or know how to setup the redstone? Then this is what you need.
This apis and programs allows you to play music from your computer using noteblocks. Using RP bundled cables and just 3 computers, you can play all the notes and instruments available in noteblocks.
You need to setup some players (2 should be enough) that send the redstone pulses to the noteblocks, and a controller that sends the data to them.

NoteBlock API
The api has the functions needed to send the data to the players.
It splits the notes and sends them to the corresponding computer.
Functions:
Spoiler

Download: pastebin (code: U0r5Hj38)
Code:
Spoiler

NoteBlock Player
This is what actually plays the noteblocks, by sending redstone pulses to the corresponding noteblock.
It receives messages over rednet from the controller, then decodes the message and plays the corresponding notes and instruments.

Download: pastebin (code: PdG4imtY)
Code:
Spoiler

Setup
Spoiler

Here's an example of a setup (this is the setup I used to test):
Spoiler

NBPlayer
With this program you can play songs stored in files. The format of the files is a serialized table, wich is sent to the nb api to decode and send to the players.

Usage:
NBPlayer <song file>
<song file>: the file to play. It must be a path to a file with the player format.

Download: pastebin (code: WZWVS5Fz)
Code:
Spoiler

And if that's not enough, you can grab your favourite song in nbs (NoteBlock Song, from NoteBlock Studio) format and convert it or play it directly using this programs. So you can take a midi file, use NoteBlock Studio to convert it to nbs and then play it with this, no need to export to schematic files.

NBS API
This api provides functions to load nbs files and save them in the format used by the NBPlayer.
Functions:
Spoiler

Installation: save it to the root of the computer (or to /rom/apis) as "nbs".

Download: pastebin (code: 0SN5Tftz)
Code:
Spoiler

NBS Player
Loads an nbs file and then it plays it. It's recommended to use the NBSConverter and NBPlayer, since the loading can take a while for long songs.

Usage:
NBSPlayer <nbs file>
<nbs file>: the nbs file to play

Example:
NBSPlayer MySong.nbs

Download: pastebin (code: aBWwUsWe)
Code:
Spoiler

NBSConverter
Converts a nbs file to the format used by NBPlayer. This format loads faster than nbs, so it's recommended to use it, specially for long songs.

Usage:
NBSConverter <nbs file> <output name>
<nbs file>: the path to the nbs file to convert.
<output name>: the name to use when saving the converted song.

Example:
NBSConverter MySong.nbs MySong
It will convert the file MySong.nbs and save it as MySong

Download: pastebin (code: 9cCAJtgm)
Code:
Spoiler

Ok, hope you enjoy it :P/>
Any feedback is welcome.

#2 cant_delete_account

  • Members
  • 484 posts

Posted 03 July 2012 - 08:35 PM

This is awesome! Especially the nbs converter.

#3 CAHbl4

  • Members
  • 1 posts

Posted 05 July 2012 - 12:01 AM

NBS API line 129:

Quote

while nextTick(file) do
should be:

Quote

while nextTick(file, tSong) do

NBSconvert line 37:

Quote

local ok, err = nbs.save(tSong, tArgs[2])
should be:

Quote

local ok, err = nbs.saveSong(tSong, tArgs[2])

And when i try to convert nbs to nb i receive error message:

Quote

textutils:112: Cannot serialize table with recursive entries

ComputerCraft v1.33
CraftOS 1.3

#4 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 05 July 2012 - 01:14 AM

View PostCAHbl4, on 05 July 2012 - 12:01 AM, said:

NBS API line 129:

Quote

while nextTick(file) do
should be:

Quote

while nextTick(file, tSong) do

NBSconvert line 37:

Quote

local ok, err = nbs.save(tSong, tArgs[2])
should be:

Quote

local ok, err = nbs.saveSong(tSong, tArgs[2])

And when i try to convert nbs to nb i receive error message:

Quote

textutils:112: Cannot serialize table with recursive entries

ComputerCraft v1.33
CraftOS 1.3
Thanks, already fixed. It was due to some last minute changes to the code. The serialization problem was because I tested it with another serialization function, wich can handle recursive tables and makes the result smaller than the one used in CraftOS, it should be fixed now.

#5 Theking4562

  • New Members
  • 3 posts
  • LocationIn my server

Posted 01 August 2012 - 05:58 AM

You did a Great job explaing how to set up the system but when i load a program exp:"NoteBlockStudio converter" it gives me Attached Image: 2012-08-01_01.55.02.png and i'am using tekkit and a offcial note block studio song

Ps: my tilte speaks the truth

#6 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 01 August 2012 - 02:35 PM

View PostTheking4562, on 01 August 2012 - 05:58 AM, said:

You did a Great job explaing how to set up the system but when i load a program exp:"NoteBlockStudio converter" it gives me Attachment 2012-08-01_01.55.02.png and i'am using tekkit and a offcial note block studio song

Ps: my tilte speaks the truth
It looks like the nbs file is missing, check that you placed it in the root folder and it's named nbs, it won't find it otherwise. Also, reboot the computer so it can reload the api.

#7 Theking4562

  • New Members
  • 3 posts
  • LocationIn my server

Posted 01 August 2012 - 09:23 PM

what do you mean my root folder , put it directly in lua or make sure the folders exp:/rom/Nbs exist or the extension is .nbs
Ps: the api you made shows up when i lanch command: apis
Pss: can you make a detail written/vidio tututriol on the setup in your world

#8 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 01 August 2012 - 09:54 PM

The api files must be named nb and nbs (in lowercase). If you put them inside rom/apis, they should be loaded at startup and you'll see them when using the "apis" program. If you see them (and the names are right), then the programs should work.
I'll try to make a more detailed tutorial (maybe a video), but I'm bussy now, so it will take some time.

#9 Theking4562

  • New Members
  • 3 posts
  • LocationIn my server

Posted 01 August 2012 - 11:51 PM

Thanks the api are working
and i hope i'am not troubling you to much
but where the root to put the songs for conversions (without the file path nonsense) exp:/rom/ or /lua/ because i'am now getting error cannot open file while converting
Ps: you set the beats left-right lowest to highest , correct?

#10 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 02 August 2012 - 01:04 AM

View PostTheking4562, on 01 August 2012 - 11:51 PM, said:

but where the root to put the songs for conversions (without the file path nonsense) exp:/rom/ or /lua/ because i'am now getting error cannot open file while converting
The root of the computer is the directory where all the computer files are. To put a file there (outside the game) you need to go to .minecraft/saves/<YourWorld>/computer/<Computer ID> and copy it there.

View PostTheking4562, on 01 August 2012 - 11:51 PM, said:

Ps: you set the beats left-right lowest to highest , correct?
I have them right-left (looking from the front) lowest to highest, but you can change that in the config.

#11 TundraFish

  • New Members
  • 15 posts

Posted 05 August 2012 - 05:27 PM

When I try to use the NBSConverter it says:
nbs:72: bad argument: table expected, got nil

Which is weird, since there's only an 'end' there

EDIT: Nevermind. I used the pastebin version and restarted the server


The player skips some notes on fast songs. It's a little bit annoying. Is there a way to fix this?

#12 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 05 August 2012 - 08:38 PM

View PostLeonardoas111, on 05 August 2012 - 05:27 PM, said:

The player skips some notes on fast songs. It's a little bit annoying. Is there a way to fix this?
The problem is that redstone pulses can't be too short, or the noteblock won't play the note. You can try to lower the pulse duration in the config, but it may skip more notes or just don't play. If it doesn't work, you'll have to increase the tempo of the song, it will play slower but won't skip any notes.

#13 TundraFish

  • New Members
  • 15 posts

Posted 06 August 2012 - 11:00 PM

View PostMysticT, on 05 August 2012 - 08:38 PM, said:

View PostLeonardoas111, on 05 August 2012 - 05:27 PM, said:

The player skips some notes on fast songs. It's a little bit annoying. Is there a way to fix this?
The problem is that redstone pulses can't be too short, or the noteblock won't play the note. You can try to lower the pulse duration in the config, but it may skip more notes or just don't play. If it doesn't work, you'll have to increase the tempo of the song, it will play slower but won't skip any notes.

The weird thing is that when I lower the pulse duration, the piano works perfectly, but the bass doesn't play if the piano is playing too many notes.

EDIT: Can I make one computer for each instrument?

#14 MysticT

    Lua Wizard

  • Members
  • 1,597 posts

Posted 07 August 2012 - 12:27 AM

Hmm, that's weird. I'll look into it.

View PostLeonardoas111, on 06 August 2012 - 11:00 PM, said:

EDIT: Can I make one computer for each instrument?
Yes, but it would require some changes to the code. It should work better that way, so I'll try to make it an option in the config.

#15 turkeygiblets

  • New Members
  • 1 posts

Posted 08 August 2012 - 01:27 PM

Awesome stuff here.

I did have issues with missing notes for fast songs though, so I had to tweak it a bit, first I tried splitting the pulse durations for on and off, which helped a bit(only needs to be off for 0.01 it seems and it still works ok), then I split the computers based on instruments, which helped a bit on slow songs with lots of notes, but it still didnt help on fast songs. Finally, I managed to make it play even challenging songs like the Turkish March included with NBS almost perfectly by connecting each computer to 2 of the same instrument (even more wiring :/), and changing the clients to alternate between which they play the notes on (when it plays a note, it also turns the other set of notes off, so you dont need to wait to turn off again in each tick). Only problem now, is it tends to cause my sister on a dodgy internet connection to disconnect ;)/>

#16 master39

  • Members
  • 17 posts
  • LocationComo (Italy)

Posted 11 August 2012 - 09:47 PM

very awesome work, i made a video song using your program, and I put the link to this thread, can I put the save for download? in the save there are all your programs and a player like your's.
can you add a video section to the post and add my video?


#17 TomasJAnderson

  • New Members
  • 1 posts

Posted 16 August 2012 - 06:36 PM

Great job I must say the notes are playing flawlessly unfortunately I'm having issues with the tempo. All the songs are playing very slowly, not too sure if anybody else is experiencing this problem.

#18 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 25 September 2012 - 09:51 PM

I have been working on something like this for a while. I have not even come close to what you have. Well done.

#19 killavirus

  • New Members
  • 3 posts

Posted 12 October 2012 - 03:07 AM

Hi there,

I have built it to the best of my understanding but just get

Unknown Note: 17
playing instrument: 2 
Notes: 17 
Unknown note: 17

the format for naming the notes i am using

local tColors = {[1] = white, [2] = orange, [3] = magenta, [4] = lightBlue, [5] = yellow, [6] = lime, [7] = pink, [8] =  gray, [9] = lightGray, [10] = cyan, [11] = purple, [12] = blue, [13] = brown, [14] = green, [15] = red, [16] = black }

Many thanks

#20 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 12 October 2012 - 04:26 AM

I am trying to set this up on a server, but the server does not have redpower. How would I convert this to be used with regular redstone pulses?





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users