Skip to content

Commit

Permalink
Bootstraping xtend/xtext + Aspect
Browse files Browse the repository at this point in the history
FAMILIAR-project committed Jan 7, 2018
1 parent 72e1f12 commit f4d74d5
Showing 115 changed files with 11,800 additions and 4,156 deletions.
Binary file modified VideoGenToolSuite/bin/.VideoGenHelper.xtendbin
Binary file not shown.
Binary file modified VideoGenToolSuite/bin/.VideoGenTest1.java._trace
Binary file not shown.
Binary file modified VideoGenToolSuite/bin/.VideoGenTest1.xtendbin
Binary file not shown.
Binary file modified VideoGenToolSuite/bin/VideoGenTest1.class
Binary file not shown.
Binary file modified VideoGenToolSuite/bin/VideoGenTestJava1.class
Binary file not shown.
4 changes: 2 additions & 2 deletions VideoGenToolSuite/example1.videogen
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
@author "MIAGE 2 students"
VideoGen {

mandatory videoseq v1 "hello.mp4"
mandatory videoseq v1 "/Users/macher1/Documents/bref2.mov"
optional videoseq v2 "v2folder/v2.mp4"
alternatives v3 {
videoseq v31 "bla.mp4"
videoseq v32 "blabla.mp4"
}
mandatory videoseq v4 "coucou.mp4"
mandatory videoseq v4 "/Users/macher1/Documents/bref2.mov"
}
61 changes: 60 additions & 1 deletion VideoGenToolSuite/src/VideoGenTest1.xtend
Original file line number Diff line number Diff line change
@@ -4,6 +4,12 @@ import org.junit.Test
import org.eclipse.emf.common.util.URI

import static org.junit.Assert.*
import org.xtext.example.mydsl.videoGen.MandatoryVideoSeq
import java.io.BufferedWriter
import java.io.IOException
import java.io.OutputStreamWriter
import java.io.FileOutputStream
import org.xtext.example.mydsl.videoGen.VideoSeq

class VideoGenTest1 {

@@ -15,7 +21,60 @@ class VideoGenTest1 {
assertNotNull(videoGen)
println(videoGen.information.authorName)
// and then visit the model
// eg access video sequences: videoGen.videoseqs
// eg access video sequences:
val playlist = newArrayList()
videoGen.medias.forEach [media |

if (media instanceof VideoSeq) {
val video = (media as VideoSeq)

if (video instanceof MandatoryVideoSeq) {
val desc = video.description
playlist.add("file '" + desc.location + "'")

/*
println("Playing... " + desc.videoid)
var p = Runtime.runtime.exec("/Applications/VLC.app/Contents/MacOS/VLC --play-and-exit --no-repeat --no-loop " + desc.location + "")
p.waitFor
*/

}
}
]

var playlistStr = ""
for (String pl : playlist)
playlistStr += pl + "\n"

writeInFile("playlist.txt", playlistStr)

var Process p
var ffmpegCmd = ffmpegConcatenateCommand("/Users/macher1/git/teaching-MDE-MIAGE1718/VideoGenToolSuite/playlist.txt", "ro.mp4").toString
println(ffmpegCmd)

p = Runtime.runtime.exec(ffmpegCmd)
p.waitFor




}

def void writeInFile(String filename, String data) {
val buffer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filename), "utf-8"))
try {
buffer.write(data)
}
catch(IOException e) {
throw e
}
finally {
buffer.flush()
buffer.close()
}
}

def ffmpegConcatenateCommand(String mpegPlaylistFile, String outputPath) '''
/usr/local/bin/ffmpeg -y -f concat -safe 0 -i «mpegPlaylistFile» -c copy «outputPath»
'''
}
68 changes: 67 additions & 1 deletion VideoGenToolSuite/src/VideoGenTestJava1.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.URI;
import org.junit.Test;
import org.xtext.example.mydsl.videoGen.AlternativeVideoSeq;
import org.xtext.example.mydsl.videoGen.MandatoryVideoSeq;
import org.xtext.example.mydsl.videoGen.Media;
import org.xtext.example.mydsl.videoGen.OptionalVideoSeq;
import org.xtext.example.mydsl.videoGen.VideoDescription;
import org.xtext.example.mydsl.videoGen.VideoGeneratorModel;
import org.xtext.example.mydsl.videoGen.VideoSeq;

public class VideoGenTestJava1 {

@@ -15,8 +25,64 @@ public void testInJava1() {
System.out.println(videoGen.getInformation().getAuthorName());
// and then visit the model
// eg access video sequences:
// videoGen.getVideoseqs()
EList<Media> medias = videoGen.getMedias();

List<List<String>> allConfs = new ArrayList<List<String>>();
for (Media media : medias) {
//
if (media instanceof VideoSeq) {
VideoSeq video = (VideoSeq) media;

if (video instanceof MandatoryVideoSeq) {
System.out.println("mandatory " + video);
String id = ((MandatoryVideoSeq)video).getDescription().getVideoid();
allConfs = addVideoIdToAllConfigurations(id, allConfs);
}
/*
if (video instanceof OptionalVideoSeq) {
for (List<String> partialConf : allConfs) {
List<String> nPartialConf = new ArrayList<String>();
nPartialConf.addAll(partialConf);
nPartialConf.add(((OptionalVideoSeq)video).getDescription().getVideoid());
allConfs.add(nPartialConf);
}
}
if (video instanceof AlternativeVideoSeq) {
for (List<String> partialConf : allConfs) {
AlternativeVideoSeq alt = (AlternativeVideoSeq) video;
for (VideoDescription desc : alt.getVideodescs()) {
List<String> nPartialConf = new ArrayList<String>();
nPartialConf.addAll(partialConf);
nPartialConf.add(desc.getVideoid());
allConfs.add(nPartialConf);
}
}
}*/

}


}
System.out.println("allConfs:" + allConfs);
assertEquals(4, allConfs.size());

}

private List<List<String>> addVideoIdToAllConfigurations(String id, List<List<String>> allConfs) {

if (allConfs.isEmpty()) {
List<String> nPartialConf = new ArrayList<String>();
nPartialConf.add(id);
allConfs.add(nPartialConf);
}
else {
System.out.println("" + allConfs);
for (List<String> partialConf : allConfs) {
partialConf.add(id);
}
}
List<List<String>> nAllConfs = new ArrayList<List<String>>(allConfs);
return nAllConfs;
}

}
Binary file modified VideoGenToolSuite/xtend-gen/.VideoGenHelper.xtendbin
Binary file not shown.
Binary file modified VideoGenToolSuite/xtend-gen/.VideoGenTest1.java._trace
Binary file not shown.
Binary file modified VideoGenToolSuite/xtend-gen/.VideoGenTest1.xtendbin
Binary file not shown.
81 changes: 78 additions & 3 deletions VideoGenToolSuite/xtend-gen/VideoGenTest1.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,90 @@
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.function.Consumer;
import org.eclipse.emf.common.util.URI;
import org.eclipse.xtend2.lib.StringConcatenation;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.junit.Assert;
import org.junit.Test;
import org.xtext.example.mydsl.videoGen.MandatoryVideoSeq;
import org.xtext.example.mydsl.videoGen.Media;
import org.xtext.example.mydsl.videoGen.VideoDescription;
import org.xtext.example.mydsl.videoGen.VideoGeneratorModel;
import org.xtext.example.mydsl.videoGen.VideoSeq;

@SuppressWarnings("all")
public class VideoGenTest1 {
@Test
public void testLoadModel() {
final VideoGeneratorModel videoGen = new VideoGenHelper().loadVideoGenerator(URI.createURI("example1.videogen"));
Assert.assertNotNull(videoGen);
InputOutput.<String>println(videoGen.getInformation().getAuthorName());
try {
final VideoGeneratorModel videoGen = new VideoGenHelper().loadVideoGenerator(URI.createURI("example1.videogen"));
Assert.assertNotNull(videoGen);
InputOutput.<String>println(videoGen.getInformation().getAuthorName());
final ArrayList<String> playlist = CollectionLiterals.<String>newArrayList();
final Consumer<Media> _function = (Media media) -> {
if ((media instanceof VideoSeq)) {
final VideoSeq video = ((VideoSeq) media);
if ((video instanceof MandatoryVideoSeq)) {
final VideoDescription desc = ((MandatoryVideoSeq)video).getDescription();
String _location = desc.getLocation();
String _plus = ("file \'" + _location);
String _plus_1 = (_plus + "\'");
playlist.add(_plus_1);
}
}
};
videoGen.getMedias().forEach(_function);
String playlistStr = "";
for (final String pl : playlist) {
String _playlistStr = playlistStr;
playlistStr = (_playlistStr + (pl + "\n"));
}
this.writeInFile("playlist.txt", playlistStr);
Process p = null;
String ffmpegCmd = this.ffmpegConcatenateCommand("/Users/macher1/git/teaching-MDE-MIAGE1718/VideoGenToolSuite/playlist.txt", "ro.mp4").toString();
InputOutput.<String>println(ffmpegCmd);
p = Runtime.getRuntime().exec(ffmpegCmd);
p.waitFor();
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}

public void writeInFile(final String filename, final String data) {
try {
FileOutputStream _fileOutputStream = new FileOutputStream(filename);
OutputStreamWriter _outputStreamWriter = new OutputStreamWriter(_fileOutputStream, "utf-8");
final BufferedWriter buffer = new BufferedWriter(_outputStreamWriter);
try {
buffer.write(data);
} catch (final Throwable _t) {
if (_t instanceof IOException) {
final IOException e = (IOException)_t;
throw e;
} else {
throw Exceptions.sneakyThrow(_t);
}
} finally {
buffer.flush();
buffer.close();
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}

public CharSequence ffmpegConcatenateCommand(final String mpegPlaylistFile, final String outputPath) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/usr/local/bin/ffmpeg -y -f concat -safe 0 -i ");
_builder.append(mpegPlaylistFile);
_builder.append(" -c copy ");
_builder.append(outputPath);
_builder.newLineIfNotEmpty();
return _builder;
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit f4d74d5

Please sign in to comment.