使用說明:Lilypond 學習手冊/基本介紹

出自 NiceChord Wiki
跳至導覽 跳至搜尋

本頁是 Lilypond 基本介紹。

編譯檔案

編譯是用於處理 LilyPond 格式的輸入檔案以生成輸出檔案的術語。

輸入

  • LilyPond 使用純文字檔案作為輸入,這意味著你可以用任何文字編輯器直接開啟 LilyPond 格式檔案(副檔名為 .ly)。
  • 區分大小寫,例如:{c d e}是有效的;而{C D E}是錯誤的。

以下是簡單的範例:

文字輸入 圖形輸出
\version "2.18.2"
{
  c' e' g' e'
}
<score>

\version "2.18.2" {

 c' e' g' e'

} </score>

輸出/編譯

LilyPond 一般可輸出三種格式:

  • PDF(用於列印及觀看)
  • MIDI(通常用於播放,但 MIDI 並非聲音檔)
  • PNG(用於線上閱讀)

MacOS X

  1. 開啟 LilyPond
  2. 將檔案儲存(File > Save)
  3. 為檔案命名,例如:「text.ly」
  4. 按下上方選單的 Compile > Typeset file(快速鍵 ⌘R)
  5. 編譯完成後會產生一個 PDF 檔,通常會自動開啟

Windows

  1. 開啟 LilyPond
  2. 將檔案另存新檔(File > Save as),請勿直接儲存(Save)
  3. 為檔案命名,例如:「text.ly」
  4. 編譯共有三種方式:
    • 快按兩次「text.ly」
    • 右鍵點擊「text.ly」並選擇 「Generate PDF」
    • 將檔案拖曳到 LilyPond 圖示上
  5. 編譯完成後會產生「.pdf」和「.log」兩個檔案。

命令列

適用於任何系統。

  1. 新建一個文字檔
  2. 輸入以下測試內容:
    \version "2.18.2"
    {
      c' e' g' e'
    }
  3. 為檔案命名,例如:「text.ly」
  4. 在命令列輸入lilypond test.ly
  5. 命令列會顯示類似以下內容:
    GNU LilyPond 2.18.2
    Processing `test.ly'
    Parsing...
    Intersource lang="Tex"ting music...
    source lang="Tex"processing graphical objects...
    Solving 1 page-breaking chunks...[1: 1 pages]
    Drawing systems...
    Layout output to `test.ps'...
    Converting to `./test.pdf'...
    Success: compilation successfully completed
  6. 編譯完成後會產生一個 PDF 檔案。

LilyPond 基礎語法

音符

  • 在大括號{}中輸入小寫音名c d e f g a b)以輸入音符,以r代表休止符。
  • 每個音之間以空格分開。
代碼 結果
{c d e f g a b c}
<score>

{c d e f g a b c} </score>

{c r c r}
<score>

{c r c r} </score>

音高

  • 若無指定八度,音域預設為 C3-B3。
  • 在音名後加上'以高一個八度,加上,以低一個八度。
    • 多次使用以上符號可以改變超過一個八度。
    • 此符號的作用僅為高/低八度,並非絕對音名。
代碼 結果
{
c' d' e' f' g' a' b' c''
c, d, e, f, g, a, b, c,,
}
<score>

{ c' d' e' f' g' a' b' c c, d, e, f, g, a, b, c,, } </score>

  • 在前面加上\relative以進入相對模式。在相對模式中,每個音預設會被當成最靠近前一個音的八度。也可在\relative後方指定起始參考音。
代碼 結果
\relative {
  c' d e f g a b c
  c, d e f g a b c
}
<score>

\relative {

 c' d e f g a b c
 c, d e f g a b c

} </score>

\relative c' {
  c d e f g a b c
  c, d e f g a b c
}
<score>

\relative c' {

 c d e f g a b c
 c, d e f g a b c

} </score>

音符時值(節奏)

  • 在音名後面輸入數字以指定音符時值(預設為四分音符),沒有輸入則視為與前一個音相同。
    • 1表示全音符,2表示二分音符,4表示四分音符,以此類推。
    • .表示附點,附點的時值必須完整標明
代碼 結果
\relative c' {
  c8 c c c c4 c
  c4. c8 r4. r8
}
<score>

\relative c' {

 c8 c c c c4 c
 c4. c8 r4. r8

} </score>

\relative c' {
  c4 c c4. c8 
}
<score>

\relative c' {

 c4 c c4. c8 

} </score>

\relative c' {
  c4 c c. c8 
}
錯誤用法,無法編譯。

升降記號

  • 在前面加上\language "語言"以指定語言。
  • 升降記號的表示方式取決於檔案中指定的語言。
    • 在預設的荷蘭語模式下,在音名後加入is表示升記號,es表示降記號。
    • 在英語模式下,在音名後加入s表示升記號,f表示降記號。
    • 重升、重降都是將對應的升降號重複兩次而成。
代碼 結果
\relative c' {
  c cis d des
  c cisis d deses
}
<score>

\relative c' {

 c cis d des
 c cisis d deses

} </score>

\language "english"
\relative c' {
  c cs d df
  c css d dff
}
<score note-language="english">

\relative c' {

 c cs d df
 c css d dff

} </score>

拍號

  • 輸入\time指定拍號,預設為四四拍。
    • 4/4 為四四拍 6/8 為六八拍,以此類推。
    • 四四拍和二二拍預設使用「𝄴」和「𝄵」符號,若想使用數字須加上\numericTimeSignature(使用\defaultTimeSignature恢復預設)。
代碼 結果
\relative c' {
  \time 3/4
  c c c 
  \time 6/8
  c4. c
  \time 4/4
  c4 c c c
}
<score>

\relative c' {

 \time 3/4
 c c c 
 \time 6/8
 c4. c
 \time 4/4
 c4 c c c

} </score>

\relative c' {
  \numericTimeSignature
  c1
  \time 2/2
  c
  \defaultTimeSignature
  \time 4/4
  c
  \time 2/2
  c
}
<score>

\relative c' {

 \numericTimeSignature
 c1
 \time 2/2
 c
 \defaultTimeSignature
 \time 4/4
 c
 \time 2/2
 c

} </score>

速度標記

  • 輸入\tempo指定速度,共三種用法:
    • \tempo "任意文字"
    • \tempo 音符時值 = 速度(BPM)
    • \tempo "任意文字" 音符時值 = 速度(BPM)
代碼 結果
\relative c' {
  \time 3/4
  \tempo "Andante"
  c4 c c
  \time 6/8
  \tempo 4. = 96
  c4. c
  \time 4/4
  \tempo  "NiceChord" 4 = 120
  c4 c c c
}
<score>

\relative c' {

 \time 3/4
 \tempo "Andante"
 c4 c c
 \time 6/8
 \tempo 4. = 96
 c4. c
 \time 4/4
 \tempo  "NiceChord" 4 = 120
 c4 c c c

} </score>

譜號

  • 輸入\clef指定譜號,預設為高音譜號。
    • 高音譜號:\clef "treble"
    • 中音譜號:\clef "alto"
    • 次中音譜號:\clef "tenor"
    • 低音譜號:\clef "bass"
代碼 結果
\relative c' {
  \clef "treble"
  c1
  \clef "alto"
  c1
  \clef "tenor"
  c1
  \clef "bass"
  c1
}
<score>

\relative c' {

 \clef "treble"
 c1
 \clef "alto"
 c1
 \clef "tenor"
 c1
 \clef "bass"
 c1

} </score>

處理輸入檔案

LilyPond 與許多程式語言相似:包含版本聲明、區分大小寫、忽略(多餘的)空格。表示式用括號括起來{},註解用%%{ %}

版本聲明

描述該檔案所需的 LilyPond 版本:

\version "2.18.2"

依照慣例,版本聲明會放在檔案的最上方。版本聲明相當重要,原因如下:

  • 當 LilyPond 語法修改時自動更新輸入檔案。
  • 描述了編譯檔案所需的版本。

當輸入檔案沒有版本聲明,LilyPond 會在編譯檔案時顯示警告。

區分大小寫

大小寫很重要,例如:{c d e}是有效的;而{C D E}是錯誤的。

註解/註釋

  • 單行註解:輸入%並在後方輸入註解,輸入的內容不會被編譯。依照慣例,註解會被放在其註解的代碼上方。
  • 多行註解:輸入%{ %}並在括號內輸入註解。
代碼 結果
\relative c' {
c d e f 
%這行註解是指下面這行
g a b c
}
<score>

\relative c' { c d e f %這行註解是指下面這行 g a b c } </score>

\relative c' {
c d e f 
%{
  多行註解
  多行註解
  多行註解
  多行註解
%}
g a b c
}
<score>

\relative c' { c d e f %{

 多行註解
 多行註解
 多行註解
 多行註解

%} g a b c } </score>