Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* Left/right syllable switching works now

* Added saving
  • Loading branch information...
commit 64645cbe89fd51dadb1fff0d79b4f5f88a1a0b13 1 parent 89818ec
sbeschke sbeschke authored
0  build/classes/.netbeans_automatic_build
No changes.
BIN  build/classes/uslr/LyricsLine.class
Binary file not shown
BIN  build/classes/uslr/LyricsSyllable.class
Binary file not shown
BIN  build/classes/uslr/MetaDataLine.class
Binary file not shown
BIN  build/classes/uslr/Song.class
Binary file not shown
BIN  build/classes/uslr/USLRAboutBox.class
Binary file not shown
BIN  build/classes/uslr/USLRApp.class
Binary file not shown
BIN  build/classes/uslr/USLRView$1.class
Binary file not shown
BIN  build/classes/uslr/USLRView$2.class
Binary file not shown
BIN  build/classes/uslr/USLRView$3.class
Binary file not shown
BIN  build/classes/uslr/USLRView.class
Binary file not shown
49 src/uslr/LyricsLine.java
@@ -5,6 +5,8 @@
5 5
6 6 package uslr;
7 7
  8 +import java.io.BufferedWriter;
  9 +import java.io.IOException;
8 10 import java.util.ArrayList;
9 11 import java.util.Iterator;
10 12
@@ -46,5 +48,52 @@ public LyricsSyllable getFirstSyllable() throws Exception {
46 48 return syllables.get(0);
47 49 }
48 50
  51 + public LyricsSyllable getLastSyllable() throws Exception {
  52 + if(this.syllables.size() < 1) throw new Exception("Get last syllable on empty line");
  53 + return syllables.get(syllables.size() - 1);
  54 + }
  55 +
  56 + public LyricsSyllable getPreviousSyllable(LyricsSyllable syl) {
  57 + int index = syllables.indexOf(syl) - 1;
  58 + if(index < 0) {
  59 + return null;
  60 + }
  61 + else {
  62 + return syllables.get(index);
  63 + }
  64 + }
  65 +
  66 + public LyricsSyllable getNextSyllable(LyricsSyllable syl) {
  67 + int index = syllables.indexOf(syl) + 1;
  68 + if(index >= syllables.size()) {
  69 + return null;
  70 + }
  71 + else {
  72 + return syllables.get(index);
  73 + }
  74 + }
  75 +
  76 + /**
  77 + * @return the lineBreakMarker
  78 + */
  79 + public String getLineBreakMarker() {
  80 + return lineBreakMarker;
  81 + }
  82 +
  83 + /**
  84 + * @param lineBreakMarker the lineBreakMarker to set
  85 + */
  86 + public void setLineBreakMarker(String lineBreakMarker) {
  87 + this.lineBreakMarker = lineBreakMarker;
  88 + }
  89 +
  90 + public void write(BufferedWriter writer) throws IOException {
  91 + for(Iterator<LyricsSyllable> i = syllables.iterator(); i.hasNext();) {
  92 + i.next().write(writer);
  93 + }
  94 + writer.write(lineBreakMarker + "\n");
  95 + }
  96 +
49 97 private ArrayList<LyricsSyllable> syllables = new ArrayList<LyricsSyllable>();
  98 + private String lineBreakMarker = "";
50 99 }
7 src/uslr/LyricsSyllable.java
@@ -5,6 +5,9 @@
5 5
6 6 package uslr;
7 7
  8 +import java.io.BufferedWriter;
  9 +import java.io.IOException;
  10 +
8 11 /**
9 12 *
10 13 * @author Sebastian
@@ -36,6 +39,10 @@ public void setPrefix(String prefix) {
36 39 this.prefix = prefix;
37 40 }
38 41
  42 + public void write(BufferedWriter writer) throws IOException {
  43 + writer.write(prefix + lyrics + "\n");
  44 + }
  45 +
39 46 private LyricsLine line; /// The line this syllable belongs to.
40 47 private String prefix; /// Everything in the line before the actual lyrics.
41 48 private String lyrics; /// The bit of lyrics in this syllable.
7 src/uslr/MetaDataLine.java
@@ -5,6 +5,9 @@
5 5
6 6 package uslr;
7 7
  8 +import java.io.BufferedWriter;
  9 +import java.io.IOException;
  10 +
8 11 /**
9 12 *
10 13 * @author Sebastian
@@ -32,7 +35,9 @@ public void setValue(String value) {
32 35 this.value = value;
33 36 }
34 37
35   -
  38 + public void write(BufferedWriter writer) throws IOException {
  39 + writer.write("#" + tag + ":" + value + "\n");
  40 + }
36 41
37 42 private String tag;
38 43 private String value;
51 src/uslr/Song.java
@@ -6,7 +6,10 @@
6 6 package uslr;
7 7
8 8 import java.io.BufferedReader;
  9 +import java.io.BufferedWriter;
  10 +import java.io.IOException;
9 11 import java.util.ArrayList;
  12 +import java.util.Iterator;
10 13 import java.util.regex.Matcher;
11 14 import java.util.regex.Pattern;
12 15
@@ -24,7 +27,7 @@ public void load(BufferedReader file) throws Exception {
24 27 metadata = new ArrayList<MetaDataLine>();
25 28
26 29 // Regex to extract tag and value of a metadata item
27   - Pattern metadataPattern = Pattern.compile("^#(\\p{javaUpperCase}+):(.*)$");
  30 + Pattern metadataPattern = Pattern.compile("^#(.+):(.*)$");
28 31 // Regex to separate a line in the input file into prefix and lyrics
29 32 Pattern syllablePattern = Pattern.compile("(^. \\d+ -?\\d+ -?\\d+ )(.*)$");
30 33 LyricsLine currentLine = new LyricsLine();
@@ -49,6 +52,7 @@ public void load(BufferedReader file) throws Exception {
49 52 break;
50 53 }
51 54 case '-': // line break
  55 + currentLine.setLineBreakMarker(syllStr);
52 56 this.addLine(currentLine);
53 57 currentLine = new LyricsLine();
54 58 break;
@@ -70,6 +74,7 @@ public void load(BufferedReader file) throws Exception {
70 74 break;
71 75 }
72 76 case 'E': // end of song
  77 + currentLine.setLineBreakMarker(syllStr);
73 78 endReached = true;
74 79 break;
75 80 }
@@ -77,6 +82,16 @@ public void load(BufferedReader file) throws Exception {
77 82 syllStr = file.readLine();
78 83 if(syllStr == null) endReached = true;
79 84 }
  85 + this.addLine(currentLine);
  86 + }
  87 +
  88 + public void save(BufferedWriter writer) throws IOException {
  89 + for(Iterator<MetaDataLine> i = metadata.iterator(); i.hasNext();) {
  90 + i.next().write(writer);
  91 + }
  92 + for(Iterator<LyricsLine> i = lyrics.iterator(); i.hasNext();) {
  93 + i.next().write(writer);
  94 + }
80 95 }
81 96
82 97 public void addLine(LyricsLine line) {
@@ -98,6 +113,40 @@ public LyricsSyllable getFirstSyllable() throws Exception {
98 113 return lyrics.get(0).getFirstSyllable();
99 114 }
100 115
  116 + public LyricsSyllable getPreviousSyllable(LyricsSyllable syl) throws Exception {
  117 + LyricsLine line = syl.getLine();
  118 + LyricsSyllable newsyl = line.getPreviousSyllable(syl);
  119 + if(newsyl == null) {
  120 + int lineIdx = lyrics.indexOf(line) - 1;
  121 + if(lineIdx < 0) {
  122 + return syl;
  123 + }
  124 + else {
  125 + return lyrics.get(lineIdx).getLastSyllable();
  126 + }
  127 + }
  128 + else {
  129 + return newsyl;
  130 + }
  131 + }
  132 +
  133 + public LyricsSyllable getNextSyllable(LyricsSyllable syl) throws Exception {
  134 + LyricsLine line = syl.getLine();
  135 + LyricsSyllable newsyl = line.getNextSyllable(syl);
  136 + if(newsyl == null) {
  137 + int lineIdx = lyrics.indexOf(line) + 1;
  138 + if(lineIdx >= lyrics.size()) {
  139 + return syl;
  140 + }
  141 + else {
  142 + return lyrics.get(lineIdx).getFirstSyllable();
  143 + }
  144 + }
  145 + else {
  146 + return newsyl;
  147 + }
  148 + }
  149 +
101 150 private ArrayList<MetaDataLine> metadata;
102 151 private ArrayList<LyricsLine> lyrics;
103 152 }
15 src/uslr/USLRView.form
@@ -110,12 +110,18 @@
110 110 </Component>
111 111 <Component class="javax.swing.JButton" name="prevSyllableButton">
112 112 <Properties>
  113 + <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
  114 + <action class="uslr.USLRView" id="lyricsPanePreviousSyllable" methodName="lyricsPanePreviousSyllable"/>
  115 + </Property>
113 116 <Property name="text" type="java.lang.String" resourceKey="prevSyllableButton.text"/>
114 117 <Property name="name" type="java.lang.String" value="prevSyllableButton" noResource="true"/>
115 118 </Properties>
116 119 </Component>
117 120 <Component class="javax.swing.JButton" name="nextSyllableButton">
118 121 <Properties>
  122 + <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
  123 + <action class="uslr.USLRView" id="lyricsPaneNextSyllable" methodName="lyricsPaneNextSyllable"/>
  124 + </Property>
119 125 <Property name="text" type="java.lang.String" resourceKey="nextSyllableButton.text"/>
120 126 <Property name="name" type="java.lang.String" value="nextSyllableButton" noResource="true"/>
121 127 </Properties>
@@ -231,6 +237,15 @@
231 237 <Property name="name" type="java.lang.String" value="openMenuItem" noResource="true"/>
232 238 </Properties>
233 239 </MenuItem>
  240 + <MenuItem class="javax.swing.JMenuItem" name="jMenuItem1">
  241 + <Properties>
  242 + <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
  243 + <action class="uslr.USLRView" id="saveSongAction" methodName="saveSongAction"/>
  244 + </Property>
  245 + <Property name="text" type="java.lang.String" resourceKey="jMenuItem1.text"/>
  246 + <Property name="name" type="java.lang.String" value="jMenuItem1" noResource="true"/>
  247 + </Properties>
  248 + </MenuItem>
234 249 <MenuItem class="javax.swing.JMenuItem" name="exitMenuItem">
235 250 <Properties>
236 251 <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
66 src/uslr/USLRView.java
@@ -12,9 +12,12 @@
12 12 import java.awt.event.ActionEvent;
13 13 import java.awt.event.ActionListener;
14 14 import java.io.BufferedReader;
  15 +import java.io.BufferedWriter;
15 16 import java.io.File;
16 17 import java.io.FileInputStream;
  18 +import java.io.FileOutputStream;
17 19 import java.io.InputStreamReader;
  20 +import java.io.OutputStreamWriter;
18 21 import java.nio.charset.Charset;
19 22 import javax.swing.Timer;
20 23 import javax.swing.Icon;
@@ -124,6 +127,7 @@ private void initComponents() {
124 127 menuBar = new javax.swing.JMenuBar();
125 128 javax.swing.JMenu fileMenu = new javax.swing.JMenu();
126 129 openMenuItem = new javax.swing.JMenuItem();
  130 + jMenuItem1 = new javax.swing.JMenuItem();
127 131 javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
128 132 javax.swing.JMenu helpMenu = new javax.swing.JMenu();
129 133 javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
@@ -145,13 +149,15 @@ private void initComponents() {
145 149 currentLineField.setText(resourceMap.getString("currentLineField.text")); // NOI18N
146 150 currentLineField.setName("currentLineField"); // NOI18N
147 151
  152 + javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(uslr.USLRApp.class).getContext().getActionMap(USLRView.class, this);
  153 + prevSyllableButton.setAction(actionMap.get("lyricsPanePreviousSyllable")); // NOI18N
148 154 prevSyllableButton.setText(resourceMap.getString("prevSyllableButton.text")); // NOI18N
149 155 prevSyllableButton.setName("prevSyllableButton"); // NOI18N
150 156
  157 + nextSyllableButton.setAction(actionMap.get("lyricsPaneNextSyllable")); // NOI18N
151 158 nextSyllableButton.setText(resourceMap.getString("nextSyllableButton.text")); // NOI18N
152 159 nextSyllableButton.setName("nextSyllableButton"); // NOI18N
153 160
154   - javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(uslr.USLRApp.class).getContext().getActionMap(USLRView.class, this);
155 161 getCharButton.setAction(actionMap.get("lyricsPaneGetChar")); // NOI18N
156 162 getCharButton.setText(resourceMap.getString("getCharButton.text")); // NOI18N
157 163 getCharButton.setName("getCharButton"); // NOI18N
@@ -250,6 +256,11 @@ private void initComponents() {
250 256 openMenuItem.setName("openMenuItem"); // NOI18N
251 257 fileMenu.add(openMenuItem);
252 258
  259 + jMenuItem1.setAction(actionMap.get("saveSongAction")); // NOI18N
  260 + jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
  261 + jMenuItem1.setName("jMenuItem1"); // NOI18N
  262 + fileMenu.add(jMenuItem1);
  263 +
253 264 exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
254 265 exitMenuItem.setName("exitMenuItem"); // NOI18N
255 266 fileMenu.add(exitMenuItem);
@@ -389,7 +400,7 @@ public void loadLyricsFile(File lyricsFile) {
389 400 newLyricsTextArea.setText(lyrics);
390 401 }
391 402 catch(Exception x) {
392   - log(x.getLocalizedMessage());
  403 + log("Exception: " + x.getLocalizedMessage());
393 404 }
394 405 }
395 406
@@ -397,6 +408,9 @@ public void setCurrentSyllable(LyricsSyllable syllable) {
397 408 this.currentSyllable = syllable;
398 409 editLyricsField.setText("");
399 410 currentLineField.setText(syllable.getLine().getLyrics(syllable));
  411 + editLyricsField.setText(syllable.getLyrics());
  412 + editLyricsField.selectAll();
  413 + editLyricsField.requestFocusInWindow();
400 414 }
401 415
402 416 @Action
@@ -419,10 +433,56 @@ public void lyricsPaneSkipChar() {
419 433 newLyricsTextArea.setText(newLyricsTextArea.getText().substring(1).trim());
420 434 }
421 435
  436 + @Action
  437 + public void lyricsPaneNextSyllable() {
  438 + if(currentSyllable == null) return;
  439 + try {
  440 + currentSyllable.setLyrics(editLyricsField.getText());
  441 + setCurrentSyllable(loadedSong.getNextSyllable(currentSyllable));
  442 + }
  443 + catch(Exception x) {
  444 + log("Exception:" + x.getMessage());
  445 + }
  446 + }
  447 +
  448 + @Action
  449 + public void lyricsPanePreviousSyllable() {
  450 + if(currentSyllable == null) return;
  451 + try {
  452 + currentSyllable.setLyrics(editLyricsField.getText());
  453 + setCurrentSyllable(loadedSong.getPreviousSyllable(currentSyllable));
  454 + }
  455 + catch(Exception x) {
  456 + log("Exception:" + x.getMessage());
  457 + }
  458 + }
  459 +
  460 + @Action
  461 + public void saveSongAction() {
  462 + if(loadedSong == null) return;
  463 + JFrame mainFrame = USLRApp.getApplication().getMainFrame();
  464 + int returnVal = fileChooser.showSaveDialog(mainFrame);
  465 + File targetFile = fileChooser.getSelectedFile();
  466 + try {
  467 + log("Saving song as: " + targetFile.getCanonicalPath());
  468 + FileOutputStream fos = new FileOutputStream(targetFile);
  469 + OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
  470 + BufferedWriter bw = new BufferedWriter(osw);
  471 + loadedSong.save(bw);
  472 + bw.close();
  473 + osw.close();
  474 + fos.close();
  475 + }
  476 + catch(Exception x) {
  477 + log("Error while saving: " + x.getLocalizedMessage());
  478 + }
  479 + }
  480 +
422 481 // Variables declaration - do not modify//GEN-BEGIN:variables
423 482 private javax.swing.JFormattedTextField currentLineField;
424 483 private javax.swing.JTextField editLyricsField;
425 484 private javax.swing.JButton getCharButton;
  485 + private javax.swing.JMenuItem jMenuItem1;
426 486 private javax.swing.JScrollPane jScrollPane1;
427 487 private javax.swing.JScrollPane jScrollPane2;
428 488 private javax.swing.JTabbedPane jTabbedPane1;
@@ -451,7 +511,7 @@ public void lyricsPaneSkipChar() {
451 511 private JDialog aboutBox;
452 512
453 513 private final byte[] utf8Bom = {(byte)0xef, (byte)0xbb, (byte)0xbf};
454   - private final JFileChooser fileChooser = new JFileChooser("/media/Volume/ultrastar/Ultrastar Deluxe/songs/Korean");
  514 + private final JFileChooser fileChooser = new JFileChooser("/home/sebastian/arbeit/ussongs/");
455 515 private File loadedFile = null;
456 516 private Song loadedSong = null;
457 517
7 src/uslr/resources/USLRView.properties
@@ -51,3 +51,10 @@ lyricsPaneGetChar.Action.text=
51 51 lyricsPaneGetChar.Action.shortDescription=
52 52 lyricsPaneSkipChar.Action.text=
53 53 lyricsPaneSkipChar.Action.shortDescription=
  54 +lyricsPaneNextSyllable.Action.text=
  55 +lyricsPaneNextSyllable.Action.shortDescription=
  56 +lyricsPanePreviousSyllable.Action.text=
  57 +lyricsPanePreviousSyllable.Action.shortDescription=
  58 +jMenuItem1.text=Save as...
  59 +saveSongAction.Action.shortDescription=
  60 +saveSongAction.Action.text=

0 comments on commit 64645cb

Please sign in to comment.
Something went wrong with that request. Please try again.