Lyrics Macro

Last modified by Andreea Popescu on 2021/03/17 21:56

cogMacro for displaying Lyrics and guitar chords
TypeJAR
Category
Developed by

Matthias Wegner

Rating
1 Votes
LicenseGNU Lesser General Public License 2.1
Compatibility

Greater than 5.1.

Installable with the Extension Manager

Description

The Lyrics Macro allows you to display lyrics and chords of songs. Features are

  • Generating Chord-Fret-Diagrams (as HTML-Canvas)
  • Capo can be used to convert the chords to the correct fret
  • For print all unneeded information is hidden
  • The style of the lyrics can be changed by a css
  • The "inner" title of the document is changed by the title which is named in the macro
  • The score of the song is automatically calculated
  • Download OnSong-FileFormat to Import to iPhone/iPad-App OnSong

Screen.jpg

In the macro the chord-pro-format is used.

{{lyrics}}
{number: A001}
{title: Meine Seele preist}
{artist: Albert Frey}
{ccli: 4895866}

Meine [Em]Seele preist die [D/E]Größe des Herrn,
es [C7]jubelt mein Geist über [G/D]Gott, meinen [D]Retter.
Meine [Em]Niedrigkeit hat er [D/E]angesehn,
für [C7]alle Zeit preisen mich [G/D]selig alle Ge[D]schlechter.

{start_of_chorus}
Gott hat [G]Gro[D]ßes an [B7m]mir ge[C]tan
und sein [G]Na[D]me ist [C]heilig.
Sein Er[G]bar[D]men hört [B7m]niemals [C]auf,
es gilt [G]al[D]len, die ihn [Em]fürchten.
{end_of_chorus}

Er [Em]hebt seinen Arm, fegt die [D/E]Mächtigen fort,
stürzt die [C7]Stolzen vom Thron, richtet [G/D]auf die Unter[D]drückten.
Er macht [Em]Hungernde satt, schickt die [D/E]Reichen fort.
Er [C7]denkt an sein Volk, so wie [G/D]er es ver[D]heissen.

{copyright:(c) 1997 SCM Hänssler, 71087 Holzgerlingen für Immanuel Music, Ravensburg}
{{/lyrics}}

Parameters

  • {start_of_chorus}, {end_of_chorus}: All text inside the chorus is placed a little bit right
  • {copyright}: Places the copyright information in the footer
  • {ccli}: Places a link to SongSelect with the correct ccli-no
  • {scale}: Scales the fret-diagrams in the given ratio. Default is 0.5
  • {number}: Set a id or number to the song. By default this is placed in the title with X) Title
  • {title}: Title of the song
  • {artist}: Artist of the song

Indexing

Because it would be nice to use all songs a object model is accessible, so you can use the objects. Put the following code in a new page and watch.

{{velocity}}
$xwiki.ssfx.use("js/xwiki/table/table.css")
$xwiki.jsfx.use("js/xwiki/table/tablefilterNsort.js", true)
{{/velocity}}

{{groovy}}
  import org.xwiki.rendering.lyrics.Lyrics;
   println("(% class=\"grid sortable filterable doOddEven\" id=\"tableid\" %)")
   println("(% class=\"sortHeader\" %)|=Lyrics|=Artist")
  for (Lyrics lyrics: services.component.getComponentManager().getInstanceList(Lyrics.class)) {
      println("|[["+lyrics.getTitle()+">>"+lyrics.getDocument()+"]]|"+lyrics.getArtist())
   }
{{/groovy}}

{{lyricsindex mode="title"/}}

Lyricsindex is a Macro which creates an Index-Register of all Lyrics

  • mode="title": Sorts all Songs by Title (without Number)
  • mode="artist": Sorts all Songs by Artist

Playlist

If you want to create a dynamic playlist you can enter a title or a document name. If it contains lyrics it will be displayed in the given order. By default the Space "Songs" is searched. If you want to search other spaces, please add the additional spaces to the last if-clause.

{{velocity}}
  ##
  ## PLACE HERE SONGS OF PLAYLIST IF YOU NOT WANT THEM ADD DYNAMICALLY
  ##
  #set($song1 = "A004")
  ##
  ## Read Song from Input-Form if set
  ##
  #if ("$!request.getParameter('song1')"!="")
     #set($song1 = "$!request.getParameter('song1')")
  #end
  #if ("$!request.getParameter('song2')"!="")
     #set($song2 = "$!request.getParameter('song2')")
  #end
  #if ("$!request.getParameter('song3')"!="")
     #set($song3 = "$!request.getParameter('song3')")
  #end
  #if ("$!request.getParameter('song4')"!="")
     #set($song4 = "$!request.getParameter('song4')")
  #end
  #if ("$!request.getParameter('song5')"!="")
     #set($song5 = "$!request.getParameter('song5')")
  #end
  #if ("$!request.getParameter('song6')"!="")
     #set($song6 = "$!request.getParameter('song6')")
  #end
  #if ("$!request.getParameter('song7')"!="")
     #set($song7 = "$!request.getParameter('song7')")
  #end
  #if ("$!request.getParameter('song8')"!="")
     #set($song8 = "$!request.getParameter('song8')")
  #end
  ##
  $xcontext.put("song1", $song1)
  $xcontext.put("song2", $song2)
  $xcontext.put("song3", $song3)
  $xcontext.put("song4", $song4)
  $xcontext.put("song5", $song5)
  $xcontext.put("song6", $song6)
  $xcontext.put("song7", $song7)
  $xcontext.put("song8", $song8)
  ##
  {{html}}
  <form action="" id="song">
   1: <input type="text" name="song1" value="$!song1" />
   5: <input type="text" name="song5" value="$!song5" /><BR/>
   2: <input type="text" name="song2" value="$!song2" />
   5: <input type="text" name="song6" value="$!song6" /><BR/>
   3: <input type="text" name="song3" value="$!song3" />
   7: <input type="text" name="song7" value="$!song7" /><BR/>
   4: <input type="text" name="song4" value="$!song4" />
   8: <input type="text" name="song8" value="$!song8" /><BR/>
   <input type="button" value="Set" onclick='this.form.submit();'>
  </form>
  {{/html}}
{{/velocity}}

{{groovy}}
  import org.xwiki.rendering.lyrics.Lyrics;

  List<String> songs = new ArrayList<String>();

  // Read Playlist-Songs
  for (int i=1; i<=8; i++) {
     String param = xcontext.get("song"+i)      
     if (param!=null) {
       songs.add(param)
      }
   }

  // print Lyrics in Table Cell (to get a printable version)
  for (String song : songs) {
     Lyrics lyrics = getLyrics(song)
     if (lyrics!=null){
       println("|(% style=\"font-weight:bold; font-size: 120%;\"%)"+lyrics.getTitle()+"")
       println("|{{include reference=\""+lyrics.getDocument()+"\"/}}\n")
       println("{{html}}\n\n<SPAN CLASS=\"pagebreak\"/>{{/html}}\n")
      }
   }

  // Find Lyrics by DocumentName or LyricsTitle
  public Lyrics getLyrics(String tag) {
     for (Lyrics lyrics: services.component.getComponentManager().getInstanceList(Lyrics.class)) {
         if (tag==null) {
             return null
          }
         if (tag.equals("")) {
             return null
          }
         
         if (lyrics.getTitle().toLowerCase().contains(tag.toLowerCase())) {
             return lyrics
          }
         if (lyrics.getDocument().toString().equals(tag)) {
             return lyrics
          }
         if (lyrics.getDocument().toString().equals("Songs."+tag)) {
             return lyrics
          }
      }
     return null
   }
{{/groovy}}

Prerequisites & Installation Instructions

Tags:
    

Get Connected