Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

* 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
View
No changes.
BIN  build/classes/uslr/LyricsLine.class
View
Binary file not shown
BIN  build/classes/uslr/LyricsSyllable.class
View
Binary file not shown
BIN  build/classes/uslr/MetaDataLine.class
View
Binary file not shown
BIN  build/classes/uslr/Song.class
View
Binary file not shown
BIN  build/classes/uslr/USLRAboutBox.class
View
Binary file not shown
BIN  build/classes/uslr/USLRApp.class
View
Binary file not shown
BIN  build/classes/uslr/USLRView$1.class
View
Binary file not shown
BIN  build/classes/uslr/USLRView$2.class
View
Binary file not shown
BIN  build/classes/uslr/USLRView$3.class
View
Binary file not shown
BIN  build/classes/uslr/USLRView.class
View
Binary file not shown
49 src/uslr/LyricsLine.java
View
@@ -5,6 +5,8 @@
package uslr;
+import java.io.BufferedWriter;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
@@ -46,5 +48,52 @@ public LyricsSyllable getFirstSyllable() throws Exception {
return syllables.get(0);
}
+ public LyricsSyllable getLastSyllable() throws Exception {
+ if(this.syllables.size() < 1) throw new Exception("Get last syllable on empty line");
+ return syllables.get(syllables.size() - 1);
+ }
+
+ public LyricsSyllable getPreviousSyllable(LyricsSyllable syl) {
+ int index = syllables.indexOf(syl) - 1;
+ if(index < 0) {
+ return null;
+ }
+ else {
+ return syllables.get(index);
+ }
+ }
+
+ public LyricsSyllable getNextSyllable(LyricsSyllable syl) {
+ int index = syllables.indexOf(syl) + 1;
+ if(index >= syllables.size()) {
+ return null;
+ }
+ else {
+ return syllables.get(index);
+ }
+ }
+
+ /**
+ * @return the lineBreakMarker
+ */
+ public String getLineBreakMarker() {
+ return lineBreakMarker;
+ }
+
+ /**
+ * @param lineBreakMarker the lineBreakMarker to set
+ */
+ public void setLineBreakMarker(String lineBreakMarker) {
+ this.lineBreakMarker = lineBreakMarker;
+ }
+
+ public void write(BufferedWriter writer) throws IOException {
+ for(Iterator<LyricsSyllable> i = syllables.iterator(); i.hasNext();) {
+ i.next().write(writer);
+ }
+ writer.write(lineBreakMarker + "\n");
+ }
+
private ArrayList<LyricsSyllable> syllables = new ArrayList<LyricsSyllable>();
+ private String lineBreakMarker = "";
}
7 src/uslr/LyricsSyllable.java
View
@@ -5,6 +5,9 @@
package uslr;
+import java.io.BufferedWriter;
+import java.io.IOException;
+
/**
*
* @author Sebastian
@@ -36,6 +39,10 @@ public void setPrefix(String prefix) {
this.prefix = prefix;
}
+ public void write(BufferedWriter writer) throws IOException {
+ writer.write(prefix + lyrics + "\n");
+ }
+
private LyricsLine line; /// The line this syllable belongs to.
private String prefix; /// Everything in the line before the actual lyrics.
private String lyrics; /// The bit of lyrics in this syllable.
7 src/uslr/MetaDataLine.java
View
@@ -5,6 +5,9 @@
package uslr;
+import java.io.BufferedWriter;
+import java.io.IOException;
+
/**
*
* @author Sebastian
@@ -32,7 +35,9 @@ public void setValue(String value) {
this.value = value;
}
-
+ public void write(BufferedWriter writer) throws IOException {
+ writer.write("#" + tag + ":" + value + "\n");
+ }
private String tag;
private String value;
51 src/uslr/Song.java
View
@@ -6,7 +6,10 @@
package uslr;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -24,7 +27,7 @@ public void load(BufferedReader file) throws Exception {
metadata = new ArrayList<MetaDataLine>();
// Regex to extract tag and value of a metadata item
- Pattern metadataPattern = Pattern.compile("^#(\\p{javaUpperCase}+):(.*)$");
+ Pattern metadataPattern = Pattern.compile("^#(.+):(.*)$");
// Regex to separate a line in the input file into prefix and lyrics
Pattern syllablePattern = Pattern.compile("(^. \\d+ -?\\d+ -?\\d+ )(.*)$");
LyricsLine currentLine = new LyricsLine();
@@ -49,6 +52,7 @@ public void load(BufferedReader file) throws Exception {
break;
}
case '-': // line break
+ currentLine.setLineBreakMarker(syllStr);
this.addLine(currentLine);
currentLine = new LyricsLine();
break;
@@ -70,6 +74,7 @@ public void load(BufferedReader file) throws Exception {
break;
}
case 'E': // end of song
+ currentLine.setLineBreakMarker(syllStr);
endReached = true;
break;
}
@@ -77,6 +82,16 @@ public void load(BufferedReader file) throws Exception {
syllStr = file.readLine();
if(syllStr == null) endReached = true;
}
+ this.addLine(currentLine);
+ }
+
+ public void save(BufferedWriter writer) throws IOException {
+ for(Iterator<MetaDataLine> i = metadata.iterator(); i.hasNext();) {
+ i.next().write(writer);
+ }
+ for(Iterator<LyricsLine> i = lyrics.iterator(); i.hasNext();) {
+ i.next().write(writer);
+ }
}
public void addLine(LyricsLine line) {
@@ -98,6 +113,40 @@ public LyricsSyllable getFirstSyllable() throws Exception {
return lyrics.get(0).getFirstSyllable();
}
+ public LyricsSyllable getPreviousSyllable(LyricsSyllable syl) throws Exception {
+ LyricsLine line = syl.getLine();
+ LyricsSyllable newsyl = line.getPreviousSyllable(syl);
+ if(newsyl == null) {
+ int lineIdx = lyrics.indexOf(line) - 1;
+ if(lineIdx < 0) {
+ return syl;
+ }
+ else {
+ return lyrics.get(lineIdx).getLastSyllable();
+ }
+ }
+ else {
+ return newsyl;
+ }
+ }
+
+ public LyricsSyllable getNextSyllable(LyricsSyllable syl) throws Exception {
+ LyricsLine line = syl.getLine();
+ LyricsSyllable newsyl = line.getNextSyllable(syl);
+ if(newsyl == null) {
+ int lineIdx = lyrics.indexOf(line) + 1;
+ if(lineIdx >= lyrics.size()) {
+ return syl;
+ }
+ else {
+ return lyrics.get(lineIdx).getFirstSyllable();
+ }
+ }
+ else {
+ return newsyl;
+ }
+ }
+
private ArrayList<MetaDataLine> metadata;
private ArrayList<LyricsLine> lyrics;
}
15 src/uslr/USLRView.form
View
@@ -110,12 +110,18 @@
</Component>
<Component class="javax.swing.JButton" name="prevSyllableButton">
<Properties>
+ <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
+ <action class="uslr.USLRView" id="lyricsPanePreviousSyllable" methodName="lyricsPanePreviousSyllable"/>
+ </Property>
<Property name="text" type="java.lang.String" resourceKey="prevSyllableButton.text"/>
<Property name="name" type="java.lang.String" value="prevSyllableButton" noResource="true"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="nextSyllableButton">
<Properties>
+ <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
+ <action class="uslr.USLRView" id="lyricsPaneNextSyllable" methodName="lyricsPaneNextSyllable"/>
+ </Property>
<Property name="text" type="java.lang.String" resourceKey="nextSyllableButton.text"/>
<Property name="name" type="java.lang.String" value="nextSyllableButton" noResource="true"/>
</Properties>
@@ -231,6 +237,15 @@
<Property name="name" type="java.lang.String" value="openMenuItem" noResource="true"/>
</Properties>
</MenuItem>
+ <MenuItem class="javax.swing.JMenuItem" name="jMenuItem1">
+ <Properties>
+ <Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
+ <action class="uslr.USLRView" id="saveSongAction" methodName="saveSongAction"/>
+ </Property>
+ <Property name="text" type="java.lang.String" resourceKey="jMenuItem1.text"/>
+ <Property name="name" type="java.lang.String" value="jMenuItem1" noResource="true"/>
+ </Properties>
+ </MenuItem>
<MenuItem class="javax.swing.JMenuItem" name="exitMenuItem">
<Properties>
<Property name="action" type="javax.swing.Action" editor="org.netbeans.modules.swingapp.ActionEditor">
66 src/uslr/USLRView.java
View
@@ -12,9 +12,12 @@
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
+import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import javax.swing.Timer;
import javax.swing.Icon;
@@ -124,6 +127,7 @@ private void initComponents() {
menuBar = new javax.swing.JMenuBar();
javax.swing.JMenu fileMenu = new javax.swing.JMenu();
openMenuItem = new javax.swing.JMenuItem();
+ jMenuItem1 = new javax.swing.JMenuItem();
javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
javax.swing.JMenu helpMenu = new javax.swing.JMenu();
javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
@@ -145,13 +149,15 @@ private void initComponents() {
currentLineField.setText(resourceMap.getString("currentLineField.text")); // NOI18N
currentLineField.setName("currentLineField"); // NOI18N
+ javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(uslr.USLRApp.class).getContext().getActionMap(USLRView.class, this);
+ prevSyllableButton.setAction(actionMap.get("lyricsPanePreviousSyllable")); // NOI18N
prevSyllableButton.setText(resourceMap.getString("prevSyllableButton.text")); // NOI18N
prevSyllableButton.setName("prevSyllableButton"); // NOI18N
+ nextSyllableButton.setAction(actionMap.get("lyricsPaneNextSyllable")); // NOI18N
nextSyllableButton.setText(resourceMap.getString("nextSyllableButton.text")); // NOI18N
nextSyllableButton.setName("nextSyllableButton"); // NOI18N
- javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(uslr.USLRApp.class).getContext().getActionMap(USLRView.class, this);
getCharButton.setAction(actionMap.get("lyricsPaneGetChar")); // NOI18N
getCharButton.setText(resourceMap.getString("getCharButton.text")); // NOI18N
getCharButton.setName("getCharButton"); // NOI18N
@@ -250,6 +256,11 @@ private void initComponents() {
openMenuItem.setName("openMenuItem"); // NOI18N
fileMenu.add(openMenuItem);
+ jMenuItem1.setAction(actionMap.get("saveSongAction")); // NOI18N
+ jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
+ jMenuItem1.setName("jMenuItem1"); // NOI18N
+ fileMenu.add(jMenuItem1);
+
exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
exitMenuItem.setName("exitMenuItem"); // NOI18N
fileMenu.add(exitMenuItem);
@@ -389,7 +400,7 @@ public void loadLyricsFile(File lyricsFile) {
newLyricsTextArea.setText(lyrics);
}
catch(Exception x) {
- log(x.getLocalizedMessage());
+ log("Exception: " + x.getLocalizedMessage());
}
}
@@ -397,6 +408,9 @@ public void setCurrentSyllable(LyricsSyllable syllable) {
this.currentSyllable = syllable;
editLyricsField.setText("");
currentLineField.setText(syllable.getLine().getLyrics(syllable));
+ editLyricsField.setText(syllable.getLyrics());
+ editLyricsField.selectAll();
+ editLyricsField.requestFocusInWindow();
}
@Action
@@ -419,10 +433,56 @@ public void lyricsPaneSkipChar() {
newLyricsTextArea.setText(newLyricsTextArea.getText().substring(1).trim());
}
+ @Action
+ public void lyricsPaneNextSyllable() {
+ if(currentSyllable == null) return;
+ try {
+ currentSyllable.setLyrics(editLyricsField.getText());
+ setCurrentSyllable(loadedSong.getNextSyllable(currentSyllable));
+ }
+ catch(Exception x) {
+ log("Exception:" + x.getMessage());
+ }
+ }
+
+ @Action
+ public void lyricsPanePreviousSyllable() {
+ if(currentSyllable == null) return;
+ try {
+ currentSyllable.setLyrics(editLyricsField.getText());
+ setCurrentSyllable(loadedSong.getPreviousSyllable(currentSyllable));
+ }
+ catch(Exception x) {
+ log("Exception:" + x.getMessage());
+ }
+ }
+
+ @Action
+ public void saveSongAction() {
+ if(loadedSong == null) return;
+ JFrame mainFrame = USLRApp.getApplication().getMainFrame();
+ int returnVal = fileChooser.showSaveDialog(mainFrame);
+ File targetFile = fileChooser.getSelectedFile();
+ try {
+ log("Saving song as: " + targetFile.getCanonicalPath());
+ FileOutputStream fos = new FileOutputStream(targetFile);
+ OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
+ BufferedWriter bw = new BufferedWriter(osw);
+ loadedSong.save(bw);
+ bw.close();
+ osw.close();
+ fos.close();
+ }
+ catch(Exception x) {
+ log("Error while saving: " + x.getLocalizedMessage());
+ }
+ }
+
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JFormattedTextField currentLineField;
private javax.swing.JTextField editLyricsField;
private javax.swing.JButton getCharButton;
+ private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTabbedPane jTabbedPane1;
@@ -451,7 +511,7 @@ public void lyricsPaneSkipChar() {
private JDialog aboutBox;
private final byte[] utf8Bom = {(byte)0xef, (byte)0xbb, (byte)0xbf};
- private final JFileChooser fileChooser = new JFileChooser("/media/Volume/ultrastar/Ultrastar Deluxe/songs/Korean");
+ private final JFileChooser fileChooser = new JFileChooser("/home/sebastian/arbeit/ussongs/");
private File loadedFile = null;
private Song loadedSong = null;
7 src/uslr/resources/USLRView.properties
View
@@ -51,3 +51,10 @@ lyricsPaneGetChar.Action.text=
lyricsPaneGetChar.Action.shortDescription=
lyricsPaneSkipChar.Action.text=
lyricsPaneSkipChar.Action.shortDescription=
+lyricsPaneNextSyllable.Action.text=
+lyricsPaneNextSyllable.Action.shortDescription=
+lyricsPanePreviousSyllable.Action.text=
+lyricsPanePreviousSyllable.Action.shortDescription=
+jMenuItem1.text=Save as...
+saveSongAction.Action.shortDescription=
+saveSongAction.Action.text=
Please sign in to comment.
Something went wrong with that request. Please try again.