io.scm 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. (require pc-ops
  2. sg1
  3. lily
  4. plants)
  5. (export chords->lilyscore
  6. chords->file
  7. lily)
  8. (def (maybe-program-path progname) -> (maybe string?)
  9. (letv ((path statuscode) (Xbacktick "which" progname))
  10. (if (zero? statuscode)
  11. path
  12. #f)))
  13. (define pdf-viewer
  14. (or (maybe-program-path "zathura")
  15. (maybe-program-path "xpdf")
  16. "xdg-open"))
  17. ;; (def (Maybe-program-path progname) -> (Maybe string?)
  18. ;; (letv ((path statuscode) (Xbacktick "which" progname))
  19. ;; (if (zero? statuscode)
  20. ;; (Just path)
  21. ;; (Nothing))))
  22. ;; (define (find-program prognames)
  23. ;; (=> (stream-map Maybe-program-path prognames)
  24. ;; (.filter Just?)
  25. ;; .first
  26. ;; .value))
  27. (define (find-program prognames)
  28. (if (null? prognames)
  29. (error "couldn't find any of the given programs")
  30. (or (maybe-program-path (car prognames))
  31. (find-program (cdr prognames)))))
  32. (define pdf-viewer (find-program '("zathura" "xpdf" "xdg-open")))
  33. ;; (define (chords->file chords)
  34. ;; (lilyscore->file (chords->lilyscore chords)))
  35. (define debug? #t)
  36. (define (chords->lilyscore chords)
  37. `((version: "2.18")
  38. (language: "english")
  39. (header: ((=tagline "")
  40. (=author "")))
  41. (score:
  42. ((new: Staff
  43. (textLengthOn: ,@chords (clef: bass) ,@morechords))
  44. (layout: ())
  45. (midi: ())))))
  46. (define (chords->file chords file)
  47. (let ((sc (chords->lilyscore chords)))
  48. (when debug?
  49. (lilyscore-display sc (current-output-port)))
  50. (lilyscore->file sc file)))
  51. (define (_lily chords)
  52. (let ((file "chords.ly"))
  53. (chords->file chords file)
  54. (when (zero? (xsystem "lilypond" file))
  55. (xsystem pdf-viewer (string-append (basename file ".ly") ".pdf")))))
  56. (define (lily chords)
  57. (_lily (.lily-annotate chords)))