Documentation
¶
Overview ¶
Package core provides the application context and core functionality for the SynapSeq text-driven audio sequencer for brainwave entrainment.
Overview ¶
This package is the public Go API for loading .spsq sequences, inspecting their metadata, rendering WAV output, streaming raw PCM, and generating HTML previews.
Supported Format ¶
SynapSeq currently supports text input in .spsq format.
Example Usage ¶
package main
import (
"log"
"os"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create application context
ctx := synapseq.NewAppContext()
// Enable verbose output (optional)
ctx = ctx.WithVerbose(os.Stderr, true)
// Load sequence (required before generating WAV or streaming)
loaded, err := ctx.Load("input.spsq")
if err != nil {
log.Fatal(err)
}
// Generate WAV file
if err := loaded.WAV("output.wav"); err != nil {
log.Fatal(err)
}
// Or render an HTML preview
previewHTML, err := loaded.Preview()
if err != nil {
log.Fatal(err)
}
_ = previewHTML
}
File Paths ¶
Input paths support:
- Local file paths: "path/to/file.spsq"
- Standard input: "-" (input only)
- HTTP/HTTPS URLs: "https://example.com/sequence.spsq"
Output methods:
- loaded.WAV("output.wav") writes a WAV file
- loaded.Stream(writer) writes raw PCM to an io.Writer
- loaded.Preview() returns HTML preview bytes
Thread Safety ¶
AppContext methods are safe for concurrent use because configuration methods return new instances rather than mutating the original context.
More Information ¶
For complete documentation and examples, see: https://github.com/synapseq-foundation/synapseq
Index ¶
- type AppContext
- type LoadedContext
- func (lc *LoadedContext) Ambiance() map[string]string
- func (lc *LoadedContext) Comments() []string
- func (lc *LoadedContext) Extends() []string
- func (lc *LoadedContext) Preview() ([]byte, error)
- func (lc *LoadedContext) RawContent() []byte
- func (lc *LoadedContext) SampleRate() int
- func (lc *LoadedContext) Stream(data io.Writer) error
- func (lc *LoadedContext) Volume() int
- func (lc *LoadedContext) WAV(outputFile string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppContext ¶
type AppContext struct {
// contains filtered or unexported fields
}
AppContext holds the configuration for the application. It provides a safe, immutable context for sequence processing. Methods that modify the context return a new instance.
func NewAppContext ¶
func NewAppContext() *AppContext
NewAppContext creates a new AppContext instance.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
fmt.Printf("AppContext created successfully\n")
}
Output: AppContext created successfully
func (*AppContext) Load ¶
func (ac *AppContext) Load(path string) (*LoadedContext, error)
Load loads the sequence from the input file.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// _ = loaded
fmt.Printf("Sequence loaded successfully\n")
}
Output: Sequence loaded successfully
func (*AppContext) Verbose ¶
func (ac *AppContext) Verbose() bool
Verbose returns whether verbose mode is enabled. When true, status output will be written to the configured writer.
func (*AppContext) WithVerbose ¶
func (ac *AppContext) WithVerbose(data io.Writer, colors bool) *AppContext
WithVerbose returns a new AppContext with verbose mode enabled. Status output will be written to the provided writer (typically os.Stderr), and colors controls whether ANSI color sequences are emitted.
Example:
ctx = ctx.WithVerbose(os.Stderr, true)
type LoadedContext ¶
type LoadedContext struct {
// contains filtered or unexported fields
}
LoadedContext holds a loaded sequence and execution settings.
func (*LoadedContext) Ambiance ¶
func (lc *LoadedContext) Ambiance() map[string]string
Ambiance returns a defensive copy of ambiance map.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Get the ambiance audio from the loaded sequence
// ambiance := loaded.Ambiance()
// fmt.Printf("Ambiance entries: %d\n", len(ambiance))
fmt.Printf("Ambiance retrieved successfully\n")
}
Output: Ambiance retrieved successfully
func (*LoadedContext) Comments ¶
func (lc *LoadedContext) Comments() []string
Comments returns a defensive copy of sequence comments.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Retrieve comments from the sequence
// for _, comment := range loaded.Comments() {
// fmt.Println(comment)
// }
fmt.Printf("Comments retrieved successfully\n")
}
Output: Comments retrieved successfully
func (*LoadedContext) Extends ¶
func (lc *LoadedContext) Extends() []string
Extends returns a defensive copy of extends list.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Get the extends list from the loaded sequence
// extends := loaded.Extends()
// fmt.Printf("Extends entries: %d\n", len(extends))
fmt.Printf("Extends list retrieved successfully\n")
}
Output: Extends list retrieved successfully
func (*LoadedContext) Preview ¶
func (lc *LoadedContext) Preview() ([]byte, error)
Preview renders the loaded sequence as an HTML preview.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Generate the HTML preview bytes
// previewHTML, err := loaded.Preview()
// if err != nil {
// log.Fatal(err)
// }
// _ = previewHTML
fmt.Printf("HTML preview bytes generated successfully\n")
}
Output: HTML preview bytes generated successfully
func (*LoadedContext) RawContent ¶
func (lc *LoadedContext) RawContent() []byte
RawContent returns a defensive copy of raw content.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Get the raw content of the loaded sequence
// rawContent := loaded.RawContent()
// fmt.Printf("Raw Content Length: %d bytes\n", len(rawContent))
fmt.Printf("Raw content retrieved successfully\n")
}
Output: Raw content retrieved successfully
func (*LoadedContext) SampleRate ¶
func (lc *LoadedContext) SampleRate() int
SampleRate returns the sample rate from the loaded sequence options.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Get the sample rate from the loaded sequence
// sampleRate := loaded.SampleRate()
// fmt.Printf("Sample Rate: %d Hz\n", sampleRate)
fmt.Printf("Sample rate retrieved successfully\n")
}
Output: Sample rate retrieved successfully
func (*LoadedContext) Stream ¶
func (lc *LoadedContext) Stream(data io.Writer) error
Stream generates the raw audio stream from the loaded sequence.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Stream the RAW data to standard output (44100 Hz [default], 16-bit, stereo)
// Replace with an io.Writer, e.g., os.Stdout
// if err := loaded.Stream(os.Stdout); err != nil {
// log.Fatal(err)
// }
fmt.Printf("RAW data streamed successfully\n")
}
Output: RAW data streamed successfully
func (*LoadedContext) Volume ¶
func (lc *LoadedContext) Volume() int
Volume returns the volume from the loaded sequence options.
Example ¶
package main
import (
"fmt"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
_ = ctx
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Get the volume from the loaded sequence
// volume := loaded.Volume()
// fmt.Printf("Volume: %d\n", volume)
fmt.Printf("Volume retrieved successfully\n")
}
Output: Volume retrieved successfully
func (*LoadedContext) WAV ¶
func (lc *LoadedContext) WAV(outputFile string) error
WAV generates the WAV file from the loaded sequence.
Example ¶
package main
import (
"fmt"
"os"
synapseq "github.com/synapseq-foundation/synapseq/v4/core"
)
func main() {
// Create a new application context
ctx := synapseq.NewAppContext()
// Optional: Enable verbose output
// Replace with an io.Writer, e.g., os.Stderr
ctx = ctx.WithVerbose(os.Stderr, true)
// Load the sequence
// loaded, err := ctx.Load("input.spsq")
// if err != nil {
// log.Fatal(err)
// }
// Generate the WAV file
// if err := loaded.WAV("output.wav"); err != nil {
// log.Fatal(err)
// }
fmt.Printf("WAV file generated successfully\n")
}
Output: WAV file generated successfully