nbs

package module
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 6 Imported by: 0

README

nbs

A note block song parser for legacy Note Block Studio and Open Note Block Studio.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instrument

type Instrument int

Instrument is one of the instruments supported through the NBS format.

const (
	InstrumentHarp Instrument = iota
	InstrumentBass
	InstrumentBassDrum
	InstrumentSnare
	InstrumentHat
	InstrumentGuitar
	InstrumentFlute
	InstrumentBell
	InstrumentChime
	InstrumentXylophone
	InstrumentIronXylophone
	InstrumentCowBell
	InstrumentDidgeridoo
	InstrumentBit
	InstrumentBanjo
	InstrumentPling
)

The following are all supported NBS instruments.

type Layer

type Layer struct {
	// Volume is the volume of the layer.
	Volume uint8
	// Name is the name of the layer.
	Name string
	// contains filtered or unexported fields
}

Layer is a layer in the NBS data.

func NewLayer

func NewLayer() *Layer

NewLayer initializes a new layer.

func (*Layer) Note

func (l *Layer) Note(tick int64) (note Note, ok bool)

Note gets a note at a tick.

func (*Layer) SetNote

func (l *Layer) SetNote(tick int64, note Note)

SetNote sets a note at a tick.

type Note

type Note struct {
	// Instrument is the instrument intended to be used.
	Instrument Instrument
	// Key is the key the note should be played on.
	Key int
}

Note is a note in a note block song.

func (Note) Sound

func (n Note) Sound() sound.Note

Sound converts the Note to a sound.Note so that it may be played as a soon in Dragonfly.

type Player

type Player struct {
	// C receives a Note everytime the Song being played by the Player reaches a point where a note should be played.
	// C is closed as soon as the song ends or when Player.Stop() is called. It is therefore possible to iterate over
	// this channel.
	C <-chan Note
	// contains filtered or unexported fields
}

Player plays a Song. Its field C may be iterated over to obtain Notes from the song whenever a new Note should be played like so:

for note := range Player.C {
  fmt.Println(note)
}

The channel C will be closed when the song ends or after Player.Stop is called, meaning the loop will end.

func (*Player) Pause

func (p *Player) Pause()

Pause toggles the pause boolean. If the song is already paused, then it will resume the song. Otherwise, it will pause the song and no new notes will be played.

func (*Player) Stop

func (p *Player) Stop()

Stop stops the current song from playing. Stop closes Player.C as soon as the Song reaches its next tick.

type Song

type Song struct {
	// Title is the title of the NBS song.
	Title string
	// Description is the description of the NBS song.
	Description string
	// Author is the creator of the song.
	Author string
	// Layers contains each layer.
	Layers map[int16]*Layer
	// Length is the length of the song in ticks.
	Length int64
	// SongHeight is the amount of different layers.
	SongHeight int16
	// Speed is the speed of the song.
	Speed float32
}

Song is a decoded NBS song. A Song may be re-used safely by calling Play for every individual instance of a song being played.

func MustReadFile

func MustReadFile(file string) Song

MustReadFile reads and parses an NBS file and returns a Song that may be played using Song.Play. It panics if an error occurred during reading.

func Read

func Read(buf *bytes.Buffer) (Song, error)

Read reads NBS data from a buffer and returns a Song that may be played using Song.Play.

func ReadFile

func ReadFile(file string) (Song, error)

ReadFile reads and parses an NBS file and returns a Song that may be played using Song.Play.

func (Song) Play

func (s Song) Play() *Player

Play creates a new Player for the Song and starts it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL