Bodged Musique & server integration
This commit is contained in:
parent
14cddb8051
commit
df68d8fa9d
1
Makefile
1
Makefile
@ -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)/debug/,$(shell find musique/* -type d)))
|
||||
$(shell mkdir -p bin/$(os)/server/)
|
||||
|
17
config.mk
17
config.mk
@ -1,16 +1,17 @@
|
||||
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)
|
||||
os=macos
|
||||
else
|
||||
os=linux
|
||||
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
|
||||
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
#include <musique/interpreter/interpreter.hh>
|
||||
#include <musique/try.hh>
|
||||
|
||||
#include <server.h>
|
||||
|
||||
#include <random>
|
||||
#include <memory>
|
||||
#include <iostream>
|
||||
@ -1109,6 +1111,19 @@ static Result<Value> builtin_call(Interpreter &i, std::vector<Value> 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()
|
||||
{
|
||||
auto &global = *Env::global;
|
||||
@ -1152,6 +1167,7 @@ void Interpreter::register_builtin_functions()
|
||||
global.force_define("shuffle", builtin_shuffle);
|
||||
global.force_define("sim", builtin_sim);
|
||||
global.force_define("sort", builtin_sort);
|
||||
global.force_define("start", builtin_start);
|
||||
global.force_define("try", builtin_try);
|
||||
global.force_define("typeof", builtin_typeof);
|
||||
global.force_define("uniq", builtin_uniq);
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include <musique/unicode.hh>
|
||||
#include <musique/value/block.hh>
|
||||
|
||||
#include <server.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
extern "C" {
|
||||
#include <io.h>
|
||||
@ -171,6 +173,8 @@ struct Runner
|
||||
ensure(the == nullptr, "Only one instance of runner is supported");
|
||||
the = this;
|
||||
|
||||
ServerInit();
|
||||
|
||||
interpreter.midi_connection = &midi;
|
||||
if (output_port) {
|
||||
midi.connect_output(*output_port);
|
||||
|
@ -1,16 +1,21 @@
|
||||
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
|
||||
@echo "CC $@"
|
||||
@$(CC) $< -c -O3 -o $@
|
||||
|
||||
bin/$(os)/%.o: musique/%.cc
|
||||
bin/$(os)/%.o: musique/%.cc $(Server)
|
||||
@echo "CXX $@"
|
||||
@$(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 $@"
|
||||
@$(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))
|
||||
|
||||
|
27
server/src/musique-bridge.go
Normal file
27
server/src/musique-bridge.go
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user