lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Emacs: Playing certain midi in a multiscore lilypond-file


From: Heikki Johannes Junes
Subject: [PATCH] Emacs: Playing certain midi in a multiscore lilypond-file
Date: Thu, 13 Dec 2001 18:59:48 +0200 (EET)

If you write Theme and Variations type scores you may want to write
several scores in a single file. Correspondingly, if you have added
midi-sections the are compiled to files "x.midi", "x-1.midi", "x-2.midi"
etc. In emacs it has not been possible to separate between these files
while applying the "Midi"-command. The following patch makes this
possible. In this patch, if you invoke "Midi"-command always the score
corresponding the following (or last) "\midi" section is played. This
patch contains also some removing of double code and spelling corrections.

--- VERSION~    Wed Dec  5 20:14:57 2001
+++ VERSION     Thu Dec 13 18:34:48 2001
@@ -2,7 +2,7 @@
 MAJOR_VERSION=1
 MINOR_VERSION=5
 PATCH_LEVEL=25
-MY_PATCH_LEVEL=
+MY_PATCH_LEVEL=hjj1
 
 # use the above to send patches: MY_PATCH_LEVEL is always empty for a
 # released version.
--- ChangeLog~  Wed Dec  5 20:08:18 2001
+++ ChangeLog   Thu Dec 13 18:38:25 2001
@@ -1,3 +1,9 @@
+2001-12-13  Heikki Junes  <address@hidden>
+
+       * lilypond-mode.el (LilyPond-command-next-midi): Play next (or last)
+       midi section in the Emacs-mode, so it is possible to play certain
+       score in a multiscore lilypond-file.
+       
 2001-12-05  Han-Wen Nienhuys  <address@hidden>
 
        * bibtools/bib2html.py: Add simple bib2html convertor, and .bst
--- ../lilypond-1.5.24/lilypond-mode.el Sun Nov 18 02:08:12 2001
+++ lilypond-mode.el    Thu Dec 13 18:29:37 2001
@@ -143,12 +143,6 @@
   :group 'LilyPond
   :type 'string)
 
-(defcustom LilyPond-midi-command "timidity"
-  "Command used to play MIDI files."
-
-  :group 'LilyPond
-  :type 'string)
-
 (defcustom LilyPond-gv-command "gv -watch"
   "Command used to display PS files."
 
@@ -318,46 +312,47 @@
 )
 
 (defun LilyPond-command-midi ()
-  "View the ps output of current document."
+  "Play midi corresponding to the current document."
   (interactive)
   (LilyPond-command (LilyPond-command-menu "Midi") 'LilyPond-master-file)
 )
 
-(defun LilyPond-command-formatdvi ()
-  "Format the dvi output of the current document."
-  (interactive)
-  (LilyPond-command (LilyPond-command-menu "2Dvi") 'LilyPond-master-file)
-)
-
-(defun LilyPond-command-formatps ()
-  "Format the ps output of the current document."
-  (interactive)
-  (LilyPond-command (LilyPond-command-menu "2PS") 'LilyPond-master-file)
-)
-
-(defun LilyPond-command-smartview ()
-  "View the dvi output of current document."
-  (interactive)
-  (LilyPond-command (LilyPond-command-menu "SmartView") 'LilyPond-master-file)
-)
-
-(defun LilyPond-command-view ()
-  "View the dvi output of current document."
-  (interactive)
-  (LilyPond-command (LilyPond-command-menu "View") 'LilyPond-master-file)
-)
-
-(defun LilyPond-command-viewps ()
-  "View the ps output of current document."
-  (interactive)
-  (LilyPond-command (LilyPond-command-menu "ViewPS") 'LilyPond-master-file)
-)
-
-(defun LilyPond-command-midi ()
-  "View the ps output of current document."
-  (interactive)
-  (LilyPond-command (LilyPond-command-menu "Midi") 'LilyPond-master-file)
-)
+(defun count-rexp (start end rexp)
+  "Print number of found regular expressions in the region."
+  (interactive "r")
+  (save-excursion
+    (save-restriction
+      (narrow-to-region start end)
+      (goto-char (point-min))
+      (count-matches rexp))))
+
+(defun count-midi-words ()
+  "Print number of scores before the curser."
+  (interactive)
+  (count-rexp (point-min) (point-max) "\\\\midi"))
+ 
+(defun count-midi-words-backwards ()
+  "Print number of scores before the curser."
+  (interactive)
+  (count-rexp (point-min) (point) "\\\\midi"))
+ 
+(defun LilyPond-command-next-midi ()
+  "Play next midi score of the current document."
+  (interactive)
+  (LilyPond-compile-file 
+   (let ((allscores (count-midi-words))
+        (scores (count-midi-words-backwards))
+        (fname (LilyPond-master-file)))
+     (let ((count (string-to-number (substring scores 0 (+ (length scores) 
-12)))))
+       (concat  LilyPond-midi-command " "
+               (substring fname 0 (+ (length fname) -3)) ; suppose ".ly"
+               (if (not (string= "1 occurrences" allscores)) ; only one score
+                   (if (not (eq count 0))                    ; first score
+                       (if (string= scores allscores)        ; last score
+                           (concat "-" (number-to-string (+ count -1)))
+                         (concat "-" (number-to-string count)))))
+               ".midi")))
+   "Midi"))
 
 ;; FIXME, this is broken
 (defun LilyPond-region-file (begin end)
@@ -473,15 +468,15 @@
   (define-key LilyPond-mode-map "\C-c\C-s" 'LilyPond-command-smartview)
   (define-key LilyPond-mode-map "\C-c\C-v" 'LilyPond-command-view)
   (define-key LilyPond-mode-map "\C-c\C-p" 'LilyPond-command-viewps)
-  (define-key LilyPond-mode-map "\C-c\C-m" 'LilyPond-command-midi)
-  (define-key LilyPond-mode-map "\C-cn" 'lilypond-notes)
-  (define-key LilyPond-mode-map "\C-cs" 'lilypond-score)
+  (define-key LilyPond-mode-map "\C-c\C-m" 'LilyPond-command-next-midi)
+  (define-key LilyPond-mode-map "\C-cn" 'LilyPond-insert-tag-notes)
+  (define-key LilyPond-mode-map "\C-cs" 'LilyPond-insert-tag-score)
   )
 
 ;;; Menu Support
 
-(define-skeleton lilypond-notes
-  "Lilypond notes tag."
+(define-skeleton LilyPond-insert-tag-notes
+  "LilyPond notes tag."
   nil
 ;  (if (bolp) nil ?\n)
   "\\notes"
@@ -489,8 +484,8 @@
       (concat " \\relative " (skeleton-read "Relative: " "" str)))
   " { " _ " }")
 
-(define-skeleton lilypond-score
-  "Lilypond score tag."
+(define-skeleton LilyPond-insert-tag-score
+  "LilyPond score tag."
   nil
   (if (bolp) nil ?\n)
   "\\score {\n"
@@ -537,9 +532,9 @@
               :keys "C-c C-r" :style radio
               :selected (eq LilyPond-command-current 'LilyPond-command-region) 
]))
          '(("Insert"
-            [ "\\notes..."  lilypond-notes
+            [ "\\notes..."  LilyPond-insert-tag-notes
               :keys "C-c n" ]
-            [ "\\score..."  lilypond-score
+            [ "\\score..."  LilyPond-insert-tag-score
               :keys "C-c s" ]
             ))
 ;        (let ((file 'LilyPond-command-on-current))
@@ -554,7 +549,7 @@
          '([ "SmartView" (LilyPond-command (LilyPond-command-menu "SmartView") 
'LilyPond-master-file) :keys "C-c C-s"])
          '([ "View" (LilyPond-command (LilyPond-command-menu "View") 
'LilyPond-master-file) :keys "C-c C-v"])
          '([ "ViewPS" (LilyPond-command (LilyPond-command-menu "ViewPS") 
'LilyPond-master-file) :keys "C-c C-p"])
-         '([ "Midi" (LilyPond-command (LilyPond-command-menu "Midi") 
'LilyPond-master-file) :keys "C-c C-m"])
+         '([ "Midi" (LilyPond-command-next-midi) :keys "C-c C-m"])
          ))
 
 (defconst LilyPond-imenu-generic-re "^\\([a-zA-Z_][a-zA-Z0-9_]*\\) *="

--
      Heikki Junes




reply via email to

[Prev in Thread] Current Thread [Next in Thread]