I want to make a copy of a variable defined in a separate file, but run in
the same current-module.
The copy I make is a copy-by-reference, and in result any modifications I
apply to the copy also appear in the original.
How do I make a copy-by-value in a current-module?
More detailed example is attached to this email.
Thanks in advance!
Robert
\version "2.22.1"
% The question that bothers me and this example is about sounds: How do I copy a variable by value?
%%%%%%% file1.ly
% I keep my music organized in variables and files, like below.
trumpet-first = {c' d' e' f'}
trumpet-second = {}
\markup "Original trumpet first:"
\trumpet-first
% At the end of each file containing music I invoke a file containing score template and other scheme magic:
% \include "file2.ly" %<= contents of this file is presented below
%%%%%%% end of file1.ly
%%%%%%% file2.ly
% Here I want to fill-in empty voices, like the trumpet-second.
% I want to fill in empty voices with other existing music, but sometimes it needs some modification, like transposition.
%Since music variables are defined in a separate file (file1.ly), I access it with module-ref function.
%Then I adapt it to other voices, for example transpose. When music is prepared, I set it to the empty voice.
#(let* ((copy-of-music (module-ref (current-module) 'trumpet-first))
(transposed-music (apply transpose `(,@(event-chord-pitches #{c' des'#}) ,copy-of-music))))
(module-set! (current-module) 'trumpet-second transposed-music))
%%%%%%% end of file2.ly
% The problem is that module-ref function does not copy variable by value, but by reference. I a result, by modifying trumpet-second I also modify trumpet-first. I don't want such outcome. I want the trumpet-first voice untouched.
\markup "Filled in and transposed trumpet second:"
\trumpet-second
\markup "Trumpet first transposed, but I want it untouched (like above):"
\trumpet-first
% Can someone suggest me a way to copy a value of a variable defined in 'current module'?