Bodged Musique & server integration

This commit is contained in:
Robert Bendun 2022-12-05 22:34:40 +01:00
parent 14cddb8051
commit df68d8fa9d
6 changed files with 65 additions and 11 deletions

View File

@ -48,3 +48,4 @@ doc/wprowadzenie.html: doc/wprowadzenie.md
$(shell mkdir -p $(subst musique/,bin/$(os)/,$(shell find musique/* -type d))) $(shell mkdir -p $(subst musique/,bin/$(os)/,$(shell find musique/* -type d)))
$(shell mkdir -p $(subst musique/,bin/$(os)/debug/,$(shell find musique/* -type d))) $(shell mkdir -p $(subst musique/,bin/$(os)/debug/,$(shell find musique/* -type d)))
$(shell mkdir -p bin/$(os)/server/)

View File

@ -1,16 +1,17 @@
MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)" MAKEFLAGS="-j $(grep -c ^processor /proc/cpuinfo)"
CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result
CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/
LDFLAGS=-flto
LDLIBS= -lpthread
RELEASE_FLAGS=-O2
DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug
ifeq ($(shell uname),Darwin) ifeq ($(shell uname),Darwin)
os=macos os=macos
else else
os=linux os=linux
endif endif
CXXFLAGS:=$(CXXFLAGS) -std=c++20 -Wall -Wextra -Werror=switch -Werror=return-type -Werror=unused-result
CPPFLAGS:=$(CPPFLAGS) -Ilib/expected/ -I. -Ilib/bestline/ -Ilib/rtmidi/ -Ibin/$(os)/server/
LDFLAGS=-flto
LDLIBS= -lpthread
RELEASE_FLAGS=-O2
DEBUG_FLAGS=-O0 -ggdb -fsanitize=undefined -DDebug

View File

@ -4,6 +4,8 @@
#include <musique/interpreter/interpreter.hh> #include <musique/interpreter/interpreter.hh>
#include <musique/try.hh> #include <musique/try.hh>
#include <server.h>
#include <random> #include <random>
#include <memory> #include <memory>
#include <iostream> #include <iostream>
@ -1109,6 +1111,19 @@ static Result<Value> builtin_call(Interpreter &i, std::vector<Value> args)
return callable(i, std::move(args)); return callable(i, std::move(args));
} }
static Result<Value> builtin_start(Interpreter &interpreter, std::span<Ast> args)
{
Value ret{};
ServerBeginProtocol();
for (auto const& ast : args) {
ret = Try(interpreter.eval((Ast)ast));
}
return ret;
}
void Interpreter::register_builtin_functions() void Interpreter::register_builtin_functions()
{ {
auto &global = *Env::global; auto &global = *Env::global;
@ -1152,6 +1167,7 @@ void Interpreter::register_builtin_functions()
global.force_define("shuffle", builtin_shuffle); global.force_define("shuffle", builtin_shuffle);
global.force_define("sim", builtin_sim); global.force_define("sim", builtin_sim);
global.force_define("sort", builtin_sort); global.force_define("sort", builtin_sort);
global.force_define("start", builtin_start);
global.force_define("try", builtin_try); global.force_define("try", builtin_try);
global.force_define("typeof", builtin_typeof); global.force_define("typeof", builtin_typeof);
global.force_define("uniq", builtin_uniq); global.force_define("uniq", builtin_uniq);

View File

@ -18,6 +18,8 @@
#include <musique/unicode.hh> #include <musique/unicode.hh>
#include <musique/value/block.hh> #include <musique/value/block.hh>
#include <server.h>
#ifdef _WIN32 #ifdef _WIN32
extern "C" { extern "C" {
#include <io.h> #include <io.h>
@ -171,6 +173,8 @@ struct Runner
ensure(the == nullptr, "Only one instance of runner is supported"); ensure(the == nullptr, "Only one instance of runner is supported");
the = this; the = this;
ServerInit();
interpreter.midi_connection = &midi; interpreter.midi_connection = &midi;
if (output_port) { if (output_port) {
midi.connect_output(*output_port); midi.connect_output(*output_port);

View File

@ -1,16 +1,21 @@
Release_Obj=$(addprefix bin/$(os)/,$(Obj)) Release_Obj=$(addprefix bin/$(os)/,$(Obj))
Server=bin/$(os)/server/server.h bin/$(os)/server/server.o
$(Server) &: server/src/*.go
cd server/src/; go build -o ../../bin/$(os)/server/server.o -buildmode=c-archive
bin/$(os)/bestline.o: lib/bestline/bestline.c lib/bestline/bestline.h bin/$(os)/bestline.o: lib/bestline/bestline.c lib/bestline/bestline.h
@echo "CC $@" @echo "CC $@"
@$(CC) $< -c -O3 -o $@ @$(CC) $< -c -O3 -o $@
bin/$(os)/%.o: musique/%.cc bin/$(os)/%.o: musique/%.cc $(Server)
@echo "CXX $@" @echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $< -c
bin/$(os)/$(Target): $(Release_Obj) bin/$(os)/main.o bin/$(os)/rtmidi.o $(Bestline) bin/$(os)/$(Target): $(Release_Obj) bin/$(os)/main.o bin/$(os)/rtmidi.o $(Bestline) $(Server)
@echo "CXX $@" @echo "CXX $@"
@$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/$(os)/rtmidi.o $(Bestline) $(LDFLAGS) $(LDLIBS) @$(CXX) $(CXXFLAGS) $(RELEASE_FLAGS) $(CPPFLAGS) -o $@ $(Release_Obj) bin/$(os)/rtmidi.o $(Bestline) $(LDFLAGS) $(LDLIBS) bin/$(os)/server/server.o
Debug_Obj=$(addprefix bin/$(os)/debug/,$(Obj)) Debug_Obj=$(addprefix bin/$(os)/debug/,$(Obj))

View File

@ -0,0 +1,27 @@
package main
import (
"C"
"fmt"
"time"
)
//export ServerInit
func ServerInit() {
fmt.Println("Initializing server")
}
//export ServerBeginProtocol
func ServerBeginProtocol() {
protocol := []string {
"Make the plan",
"Execute the plan",
"Expect the plan to go off the rails",
"Throw away the plan",
}
for i, msg := range protocol {
fmt.Printf("%d. %s\n", i, msg)
time.Sleep(300 * time.Millisecond)
}
}