Skip to content

Commit 6fdfe8f

Browse files
committed
Attempt at adding alda-code function to alda-lisp
1 parent 4072849 commit 6fdfe8f

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

client/model/lisp.go

+40-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@ import (
88

99
"alda.io/client/json"
1010
log "alda.io/client/logging"
11+
12+
// FIXME: This doesn't work because the `parser` package depends on the
13+
// `model` package, so attempting to import the `parser` package _from_ the
14+
// `model` package results in a cyclic import error:
15+
//
16+
// package alda.io/client
17+
// imports alda.io/client/cmd
18+
// imports alda.io/client/code-generator
19+
// imports alda.io/client/model
20+
// imports alda.io/client/parser
21+
// imports alda.io/client/model: import cycle not allowed
22+
// package alda.io/client
23+
// imports alda.io/client/cmd
24+
// imports alda.io/client/code-generator
25+
// imports alda.io/client/model
26+
// imports alda.io/client/parser
27+
// imports alda.io/client/model: import cycle not allowed
28+
"alda.io/client/parser"
1129
)
1230

1331
// Alda includes a minimal Lisp implementation as a subset of the language, in
@@ -1005,7 +1023,7 @@ func init() {
10051023
for marking := range DynamicVolumes {
10061024
defattribute([]string{marking},
10071025
attributeFunctionSignature{
1008-
argumentTypes: []LispForm{},
1026+
argumentTypes: []LispForm{},
10091027
implementation: dynamicImplementation(marking),
10101028
},
10111029
)
@@ -1315,6 +1333,27 @@ func init() {
13151333
},
13161334
},
13171335
)
1336+
1337+
defn("alda-code",
1338+
FunctionSignature{
1339+
ArgumentTypes: []LispForm{LispString{}},
1340+
Implementation: func(args ...LispForm) (LispForm, error) {
1341+
stringLiteral := args[0].(LispString)
1342+
1343+
// FIXME: This doesn't work because of a cyclic import error. See
1344+
// comment at the top of this file for more details.
1345+
scoreUpdates, err := parser.ParseString(stringLiteral.Value)
1346+
if err != nil {
1347+
return nil, &AldaSourceError{
1348+
Context: stringLiteral.SourceContext,
1349+
Err: err,
1350+
}
1351+
}
1352+
1353+
return EventSequence{Events: scoreUpdates}, nil
1354+
},
1355+
},
1356+
)
13181357
}
13191358

13201359
// LispNil is the value nil.

client/model/notes_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -485,5 +485,23 @@ func TestNotes(t *testing.T) {
485485
expectMidiNoteNumbers(67),
486486
},
487487
},
488+
scoreUpdateTestCase{
489+
label: "alda-code notes",
490+
updates: []ScoreUpdate{
491+
PartDeclaration{Names: []string{"piano"}},
492+
LispList{Elements: []LispForm{
493+
LispSymbol{Name: "tempo"},
494+
LispNumber{Value: 120},
495+
}},
496+
LispList{Elements: []LispForm{
497+
LispSymbol{Name: "alda-code"},
498+
LispString{Value: "c+2 f+ a"},
499+
}},
500+
},
501+
expectations: []scoreUpdateExpectation{
502+
expectNoteDurations(1000, 1000, 1000),
503+
expectMidiNoteNumbers(61, 65, 68),
504+
},
505+
},
488506
)
489507
}

0 commit comments

Comments
 (0)