Commit f5b8084b authored by ludwig's avatar ludwig
Browse files

-> removed unused parameters

-> new audio concat in editor (old one was buggy)
-> removed some annoying system.out.println()

git-svn-id: https://www2.in.tum.de/repos/ttt/trunk@70 0463f305-d864-43cb-8a47-61cf597d4139
parent 93e1b090
......@@ -77,7 +77,7 @@ public class Recorder implements MessageConsumer, Closeable {
// initialize audio and video
if (lectureProfile != null)
audioVideoRecorder = new AudioRecorder(lectureProfile);
audioVideoRecorder = new AudioRecorder();
// register for shutdown
register(this);
......@@ -663,17 +663,17 @@ public class Recorder implements MessageConsumer, Closeable {
}
static String[] checkFileName(String path, String name) {
return checkFileName(path, name, true, true, true, null);
return checkFileName(path, name, true, null);
}
static String[] checkFileName(String path, String name, String ending) {
if (ending != null)
return checkFileName(path, name, false, false, false, ending);
return checkFileName(path, name, false, ending);
else
return checkFileName(path, name, true, true, true, null);
return checkFileName(path, name, true, null);
}
static String[] checkFileName(String path, String name, boolean desktop, boolean audio, boolean video, String ending) {
static String[] checkFileName(String path, String name, boolean desktop, String ending) {
File ttt = new File(path, name + Constants.desktopEndings[0]);
File custom = null;
if (ending != null)
......
......@@ -30,7 +30,6 @@ import javax.swing.JOptionPane;
import ttt.Constants;
import ttt.TTT;
import ttt.record.LectureProfile;
public class AudioRecorder {
static public int WAV_RECORD_MODE = 2;
......@@ -40,7 +39,7 @@ public class AudioRecorder {
private IAudioRecorder wavAudioRecorder;
private AudioMonitorPanel volumeLevelComponent;
public AudioRecorder(LectureProfile lectureProfile) throws IOException {
public AudioRecorder() throws IOException {
// public AudioVideoRecorder(boolean video_recording, int audioMode) throws IOException {
audioMode = WAV_RECORD_MODE;
......
......@@ -398,7 +398,7 @@ public class MP3Converter implements ControllerListener, DataSinkListener {
AudioFormat format = new AudioFormat(AudioFormat.MPEGLAYER3);
System.out.println("- set track format to: " + format);
if (!setEachTrackFormat(p, tcs, format)) {
if (!setEachTrackFormat(tcs, format)) {
System.out.println("Cannot transcode any track to: " + format);
return false;
}
......@@ -409,7 +409,7 @@ public class MP3Converter implements ControllerListener, DataSinkListener {
/**
* We'll loop through the tracks and try to find a track that can be converted to the given format.
*/
boolean setEachTrackFormat(Processor p, TrackControl tcs[], Format fmt) {
boolean setEachTrackFormat(TrackControl tcs[], Format fmt) {
Format supported[];
Format f;
......
......@@ -90,69 +90,6 @@ public class Concat implements ControllerListener, DataSinkListener {
String TRANSCODE_MSG = "The given inputs require transcoding to have a common format for concatenation.";
/**
* Main program
*/
/* public static void main(String [] args) {
Vector inputURL = new Vector();
String outputURL = null;
if (args.length == 0)
prUsage();
// Parse the arguments.
int i = 0;
while (i < args.length) {
if (args[i].equals("-o")) {
i++;
if (i >= args.length)
prUsage();
outputURL = args[i];
} else {
inputURL.addElement(args[i]);
}
i++;
}
if (inputURL.size() == 0) {
System.err.println("No input url is specified");
prUsage();
}
if (outputURL == null) {
System.err.println("No output url is specified");
prUsage();
}
// Generate the input and output media locators.
MediaLocator iml[] = new MediaLocator[inputURL.size()];
MediaLocator oml;
for (i = 0; i < inputURL.size(); i++) {
if ((iml[i] = createMediaLocator((String)inputURL.elementAt(i))) == null) {
System.err.println("Cannot build media locator from: " + inputURL);
System.exit(0);
}
}
if ((oml = createMediaLocator(outputURL)) == null) {
System.err.println("Cannot build media locator from: " + outputURL);
System.exit(0);
}
Concat concat = new Concat();
if (!concat.doIt(iml, oml)) {
System.err.println("Failed to concatenate the inputs");
}
System.exit(0);
}
*/
ContentDescriptor cd;
ProcInfo pInfo[];
......@@ -251,6 +188,7 @@ public class Concat implements ControllerListener, DataSinkListener {
}
// Set the output content descriptor on the final processor.
System.err.println("- Set output content descriptor to: " + cd);
if ((p.setContentDescriptor(cd)) == null) {
System.err.println("Failed to set the output content descriptor on the processor.");
......@@ -483,7 +421,8 @@ public class Concat implements ControllerListener, DataSinkListener {
Format origFmt = tc.getFormat();
Format newFmt, oldFmt;
Format supported[] = tc.getSupportedFormats();
for (int i = 0; i < supported.length; i++) {
if (supported[i] instanceof AudioFormat) {
......
package ttt.editor.processors;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;
/**
*
* @author Ludwig This class is meant to concat wav files.
*/
public class WavConcat {
private File[] InFiles;
private File OutFile;
byte[] header = new byte[44]; // stores the header for the wav. (wav header size is are 44 byte)
byte[] OutBuffer; //Stores the complete outfile
byte[] InBuffer; //reads each file and writes them then into the OutBuffer
byte[] Offset = new byte[44]; //used to skip the .wav header of the files
FileInputStream fileIn;
int Position = 44; //where to paste the new byte in the OutBuffer
long[] durations; //saves the duration of each AudioIn File
/**
*
* @param AudioIn The in Array of the Audio Files
* @param AudioOut The out file were to write the new Audio file to
*/
public WavConcat(File[] AudioIn, File AudioOut) {
InFiles = AudioIn;
for (File i : AudioIn) {
if(!i.toString().endsWith(".wav")) {
System.err.println("Error! Can only Concat wav files! : " + i.toString() + " is not.");
}
}
OutFile = AudioOut;
OutBuffer = new byte[calculateOutFileSize()];
durations = new long[AudioIn.length];
}
/**
* Assumes doit was already called
*
* @return return the duration of the each audio file in AudioIn
*/
public long[] getDurationNanoSeconds() {
return durations;
}
/**
* Read the AudioIn concat them and write into the AudioOut
*/
public boolean doIt() {
try {
OutFile.createNewFile();
} catch (IOException e) {
System.err.println("Couldn't create the OutFile.");
e.printStackTrace();
return false;
}
saveHeader();
readFilesIntoOutBuffer();
ManipulateHeader();
FileOutputStream fileOut;
try {
fileOut = new FileOutputStream(OutFile);
fileOut.write(OutBuffer);
fileOut.close();
} catch (FileNotFoundException e) {
// Shouldn't happen
e.printStackTrace();
return false;
} catch (IOException e) {
System.err.println("Couldn't write file");
e.printStackTrace();
return false;
}
return true;
}
/**
* Writes the new new header for the wav file
*/
private void ManipulateHeader() {
//for details information about wav headers see: https://ccrma.stanford.edu/courses/422/projects/WaveFormat/
//write the whole header Into OutBuffer
for (int i = 0; i < header.length; i++) {
OutBuffer[i] = header[i];
}
//Change the size information
byte[] t = new byte[4];
t = convertIntToByteArray((OutBuffer.length - 44));
int SubChunk = convertByteArrayToInt(t);
OutBuffer[40] = t[3];
OutBuffer[41] = t[2];
OutBuffer[42] = t[1];
OutBuffer[43] = t[0];
t = convertIntToByteArray(SubChunk + 36);
OutBuffer[4] = t[3];
OutBuffer[5] = t[2];
OutBuffer[6] = t[1];
OutBuffer[7] = t[0];
}
/**
* save the header information
*/
private void saveHeader() {
try {
fileIn = new FileInputStream(InFiles[0]);
fileIn.read(header); //save the header
} catch (FileNotFoundException e) {
System.err.println("Error reading file: " + InFiles[0].toString());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Error reading file: " + InFiles[0].toString());
e.printStackTrace();
}
}
/**
* read each file and write them into the OutBuffer
*/
private void readFilesIntoOutBuffer() {
for(File i: InFiles) {
try {
InBuffer = new byte[(int) (i.length() - Offset.length)];
fileIn = new FileInputStream(i);
fileIn.read(Offset); //skip file header
saveDuration();
fileIn.read(InBuffer);
for (int j = 0; j < InBuffer.length; j++) {
OutBuffer[j + Position] = InBuffer[j];
}
Position += InBuffer.length;
} catch (FileNotFoundException e) {
System.err.println("Error reading file: " + i.toString());
e.printStackTrace();
} catch (IOException e) {
System.err.println("Error reading file: " + i.toString());
e.printStackTrace();
}
}
}
int count = 0;
/**
* Calculate the duration from the header and save it.
*/
private void saveDuration() {
//Duration = chunk/ bitrate (chunk = informationsize)
//Reading out Bitrate
byte[] rate = new byte[4];
rate[3] = Offset[28];
rate[2] = Offset[29];
rate[1] = Offset[30];
rate[0] = Offset[31];
//Reading chunk
byte[] chunk = new byte[4];
chunk[3] = Offset[4];
chunk[2] = Offset[5];
chunk[1] = Offset[6];
chunk[0] = Offset[7];
durations[count++] = TimeUnit.SECONDS.toNanos((convertByteArrayToInt(chunk) / convertByteArrayToInt(rate)));
}
private int calculateOutFileSize(){
int size = 0;
for(File i: InFiles) {
size += i.length();
}
return size;
}
public byte[] convertIntToByteArray(int val) {
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.putInt(val);
return buffer.array();
}
public int convertByteArrayToInt(byte[] bytebuf) {
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.put(bytebuf);
return buffer.getInt(0);
}
}
package ttt.editor.tttEditor;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Stroke;
import java.awt.BasicStroke;
import java.awt.Shape;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.font.FontRenderContext;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
......@@ -78,10 +78,9 @@ public class AnnotationMessage extends Message {
final static Font FONT = new Font("SansSerif", Font.BOLD, 16);
public void writeTextAnnotaion(DataOutputStream out, boolean writeTimestamp)
public void writeTextAnnotaion(DataOutputStream out)
throws IOException {
//writeHeader(out, writeTimestamp);
out.writeByte(c);
out.writeShort(x);
out.writeShort(y);
......@@ -102,7 +101,6 @@ public class AnnotationMessage extends Message {
this.maxWidth = maxWidth;
text = txt;
System.out.println("TextAnnotation: " + text);
try {
bText = txt.getBytes("UTF-8");
} catch (UnsupportedEncodingException uee) {
......@@ -216,9 +214,9 @@ public class AnnotationMessage extends Message {
* encoding is not REMOVE
*/
public Point getRemoveCoordinates() {
if (isRemove())
return new Point(x,y);
else
if (isRemove()) {
return new Point(x,y);}
return null;
}
......@@ -334,7 +332,7 @@ public class AnnotationMessage extends Message {
if (t.size() > 0) {
ret = new AnnotationMessage[t.size()];
for (int i = 0; i < t.size(); i++)
ret[i] = (AnnotationMessage) t.get(i);
ret[i] = t.get(i);
}
return ret;
......@@ -347,7 +345,8 @@ public class AnnotationMessage extends Message {
* of the message.
* @return string representation of <code>AnnotationMessage</code>
*/
public String toString() {
@Override
public String toString() {
switch(encoding) {
case ProtocolConstants.LINE:
return ("Line:\t " + TTTEditor.getStringFromTime(timestamp,true));
......
......@@ -187,7 +187,7 @@ public class ControlPanel extends JPanel implements PlaybackEventListener {
timeSlider.setPaintTicks(true);
timeSlider.setValue(0);
timeSlider.setUI(new TimeSliderUI(timeSlider, markers, index));
timeSlider.setUI(new TimeSliderUI(markers, index));
timeSlider.setPreferredSize(new Dimension(60, 60));
timeSlider.addChangeListener(new ChangeListener() {
......@@ -292,7 +292,7 @@ public class ControlPanel extends JPanel implements PlaybackEventListener {
volumePanel.add(volumeButton);
volumePanel.add(muteBox);
return volumePanel;
} else
}
return null;
}
......@@ -412,7 +412,7 @@ public class ControlPanel extends JPanel implements PlaybackEventListener {
private MarkerList markers;
private Index index;
public TimeSliderUI(JSlider slider, MarkerList markers, Index index) {
public TimeSliderUI(MarkerList markers, Index index) {
this.markers = markers;
this.index = index;
index.addIndexListener(this);
......
......@@ -141,7 +141,7 @@ public class DetailsPanel extends JPanel {
if (extension[0] == ProtocolConstants.EXTENSION_INDEX_TABLE) {
int ch1 = extension[1];
int ch2 = extension[2];
entries = (ch1 << 8) + (ch2 << 0);;
entries = (ch1 << 8) + (ch2 << 0);
break;
}
}
......
......@@ -112,7 +112,7 @@ public class FileConnector {
*/
private int result; // placed here to be accessable in anonymous Runnable (see below)
;
public SelectionPanel selectionPanel;
public boolean connectFiles() {
......
......@@ -72,9 +72,10 @@ public abstract class Message {
* <code>Parameters</code> is set to <code>true</code>
*/
public int getTimestamp() {
if (Parameters.synchronize)
if (Parameters.synchronize) {
return (int)(timestamp * header.synchRatio);
else
}
return timestamp;
}
......@@ -145,7 +146,7 @@ public abstract class Message {
//special treatment for text Annotations
if(this.getEncoding() == ProtocolConstants.TEXT){
((AnnotationMessage)this).writeTextAnnotaion(out, true);
((AnnotationMessage)this).writeTextAnnotaion(out);
}else{
out.write(data);}
}
......
......@@ -423,7 +423,7 @@ public class TTTEditor extends JFrame {
System.out.println("Attempt to select file vetoed: " + e);
e.printStackTrace();
}
;
return frame;
}
if (desktopPane.getAllFramesInLayer(DESKTOP_LAYER).length > 0) {
......
......@@ -13,9 +13,8 @@ import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.zip.InflaterInputStream;
import javax.swing.ProgressMonitorInputStream;
import ttt.messages.Annotation;
import javax.swing.ProgressMonitorInputStream;
......@@ -188,7 +187,7 @@ public class TTTFileReader {
//parse extensions
for (int i = 0; i < fileData.extensions.size(); i++) {
byte[] extension = (byte[]) fileData.extensions.get(i);
byte[] extension = fileData.extensions.get(i);
DataInputStream ext_in = new DataInputStream(new ByteArrayInputStream(extension));
int tag = ext_in.readByte();
switch (tag) {
......@@ -281,7 +280,7 @@ public class TTTFileReader {
msg = getHextileMessageBytes(in, header, msgArea);
message = new HextileMessage(timestamp, encoding, area, msg, header);
messages.add((HextileMessage)message);
messages.add(message);
size -= msg.length;
break;
......@@ -304,7 +303,7 @@ public class TTTFileReader {
message.area = 0;
}
message = new RawMessage(timestamp, encoding, area, msg, header);
messages.add((RawMessage)message);
messages.add(message);
size -= msg.length;
break;
......@@ -325,7 +324,7 @@ public class TTTFileReader {
message.area = 0;
}
message = new CopyRectMessage(timestamp, encoding, area, msg, header);
messages.add((CopyRectMessage)message);
messages.add(message);
size -= msg.length;
break;
......@@ -340,7 +339,7 @@ public class TTTFileReader {
i = updateNRects;
message = new UnknownMessage(timestamp, encoding, msg, header);
messages.add((UnknownMessage)message);
messages.add(message);
break;
}
count++;
......@@ -420,27 +419,27 @@ public class TTTFileReader {
message.area = 0;
}
message = new HextileMessage(timestamp, encoding, area, msg, header);
messages.add((HextileMessage)message);
messages.add(message);
break;
case ProtocolConstants.EncodingRaw:
msg = new byte[size];
in.readFully(msg);
message = new RawMessage(timestamp, encoding, area, msg, header);
messages.add((RawMessage)message);
messages.add(message);
break;
case ProtocolConstants.EncodingCopyRect:
msg = new byte[size];
in.readFully(msg);
message = new CopyRectMessage(timestamp, encoding, area, msg, header);
messages.add((CopyRectMessage)message);
messages.add(message);
break;
case ProtocolConstants.EncodingTTTCursorPosition: ;
case ProtocolConstants.EncodingTTTCursorPosition:
int x = in.readUnsignedShort();
int y = in.readUnsignedShort();
message = new CursorMoveMessage(timestamp, encoding, x, y, header);
messages.add((CursorMoveMessage)message);
messages.add(message);
break;
case ProtocolConstants.EncodingTTTXCursor: ;
case ProtocolConstants.EncodingTTTXCursor:
case ProtocolConstants.EncodingTTTRichCursor:
msg = new byte[size];
in.readFully(msg);
......@@ -458,25 +457,25 @@ public class TTTFileReader {