February 8Feb 8 if I enter a string as title in defscore and export the score as xml file, the title is always followed by a number in square brackets: Title [12]. How can I get rid of this addition?Acoustic-Scale.xml
February 10Feb 10 Author With this code, I eliminate the brackets directly in the xml file: ;; Clean up titles with number-brackets generated by Opusmodus(defun clean-xml-bracket-numbers (filepath) "Remove any ' [123]' pattern from an XML file after export." (let* ((text (read-file-string filepath)) ;; Use a simpler string replacement if regex is problematic (clean (remove-bracket-numbers text))) (with-open-file (out filepath :direction :output :if-exists :supersede :if-does-not-exist :create :external-format :utf-8) (write-string clean out)) filepath))(defun remove-bracket-numbers (string) "Remove patterns like ' [123]' from string using string functions." (let ((pos 0) (result "")) (loop while (< pos (length string)) do (let ((bracket-pos (position #\[ string :start pos))) (if bracket-pos (progn (setf result (concatenate 'string result (subseq string pos bracket-pos))) ;; Check if this is a number in brackets (let ((close-pos (position #\] string :start (1+ bracket-pos)))) (if (and close-pos (every #'digit-char-p (subseq string (1+ bracket-pos) close-pos))) (setf pos (1+ close-pos)) ; Skip the bracket number (progn (setf result (concatenate 'string result "[")) (setf pos (1+ bracket-pos)))))) (progn (setf result (concatenate 'string result (subseq string pos))) (setf pos (length string)))))) result))
February 15Feb 15 Author Here is a new version of my "number cleaner-functions" for xml exports. The old version doesn't remove the space before the bracket and added a nil at the end of the file. This new one works better:(defun clean-xml-bracket-numbers (filepath) "Remove any ' [123]' pattern from an XML file after export." (let* ((text (read-file-string filepath)) ;; Remove any trailing null characters first (cleaned-text (string-right-trim (list #\null #\nul) text)) ;; Remove bracket numbers with preceding space (clean (remove-bracket-numbers cleaned-text))) (with-open-file (out filepath :direction :output :if-exists :supersede :if-does-not-exist :create :external-format :utf-8) (write-string clean out)) filepath))(defun remove-bracket-numbers (string) "Remove patterns like ' [123]' from string using string functions. Also removes the space before the bracket." (let ((pos 0) (result (make-string (length string) :element-type 'character)) (result-pos 0)) (loop while (< pos (length string)) do (let ((space-pos (position #\space string :start pos))) (if space-pos (progn ;; Copy up to the space (loop for i from pos below space-pos do (setf (char result result-pos) (char string i)) (incf result-pos)) ;; Check if next character is '[' (if (and (< (1+ space-pos) (length string)) (char= (char string (1+ space-pos)) #\[)) (let ((close-pos (position #\] string :start (+ space-pos 2)))) (if (and close-pos (every #'digit-char-p (subseq string (+ space-pos 2) close-pos))) ;; Found pattern " [123]" - skip the space and the brackets with numbers (setf pos (1+ close-pos)) ;; Not our pattern, keep the space (progn (setf (char result result-pos) #\space) (incf result-pos) (setf pos (1+ space-pos))))) ;; No bracket after space, keep the space (progn (setf (char result result-pos) #\space) (incf result-pos) (setf pos (1+ space-pos))))) ;; No more spaces, copy remaining text (progn (loop for i from pos below (length string) do (setf (char result result-pos) (char string i)) (incf result-pos)) (setf pos (length string)))))) ;; Return only the filled portion of the result string (subseq result 0 result-pos)))
February 15Feb 15 Removing the number when saving a MusicXML file can be done easily, if that’s what you’re looking for.
February 18Feb 18 Author This is exactly what's done in my posted function. Thanks. "Easy" just for coders!
Create an account or sign in to comment