Skip to content

Commit

Permalink
fix and distribution packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsx-dev committed Aug 16, 2018
1 parent ee94b88 commit 2237816
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 49 deletions.
19 changes: 16 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {

}

version = '0.0.1-SNAPSHOT'
version = '0.1.0'
ext {
appName = "pfxr"
gdxVersion = '1.9.6'
Expand Down Expand Up @@ -77,12 +77,25 @@ task dist(type: Jar) {
from files(sourceSets.main.output.classesDir)
from files(sourceSets.main.output.resourcesDir)
from {configurations.compile.collect {zipTree(it)}}
from files(project.assetsDir);

archiveName = "${appName}.jar"
manifest {
attributes 'Main-Class': project.mainClassName
}
}

dist.dependsOn classes

task distZip(type: Zip, dependsOn: dist){
from files('build/libs/'){
include 'pfxr.jar'
fileMode = 0755
}
from files('dist/'){
include "*.txt"
}
from files('.'){
include 'pd/*.pd', 'presets/*.txt', 'audio', 'assets/skins/*'
}
archiveName "${appName}-${version}.zip"
destinationDir(file("build"))
}
8 changes: 5 additions & 3 deletions src/net/mgsx/pfxr/PFXR.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

public class PFXR extends Game
{
private static final String pdPath = "pd";

public static void main (String[] arg) {
LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
config.width = 640;
config.height = 480;
config.width = 800;
config.height = 600;
new LwjglApplication(new PFXR(), config);
}

Expand All @@ -28,7 +30,7 @@ public void create () {
PdConfiguration config = new PdConfiguration();
Pd.audio.create(config);

FileHandle patch = Gdx.files.local("../pd/pfxr.pd");
FileHandle patch = Gdx.files.local(pdPath + "/pfxr.pd");

PdCanvas patchData = PdParser.parsePatch(patch);

Expand Down
76 changes: 35 additions & 41 deletions src/net/mgsx/pfxr/PFXRScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup;
import com.badlogic.gdx.scenes.scene2d.ui.Dialog;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
Expand All @@ -34,15 +35,16 @@

public class PFXRScreen extends StageScreen
{
private static final String presetPath = "presets";
private static final String audioPath = "audio";

private Array<ControlUI> sliders = new Array<ControlUI>();

private boolean disableEvents;

private WaveFormUI finalWaveRenderer;
private WaveFormUI waveFormRenderer;

private ShapeRenderer shapeRenderer;

private boolean requestUpdate, requestWaveFormUpdate;
private float updateTimeout;

Expand All @@ -63,15 +65,14 @@ public void receiveFloat(String source, float x) {

waveFormRenderer = new WaveFormUI(200, 100);

shapeRenderer = new ShapeRenderer();

skin = new Skin(Gdx.files.internal("skins/uiskin.json"));
skin = new Skin(Gdx.files.internal("assets/skins/uiskin.json"));

Table root = new Table(skin);
root.setFillParent(true);
stage.addActor(root);

Table controlsTable = new Table(skin);
controlsTable.defaults().pad(4);

for(final PfxrControl control : controls){

Expand Down Expand Up @@ -106,7 +107,7 @@ public void changed(ChangeEvent event, Actor actor) {
final TextButton bt = new TextButton(label, skin, "toggle");
group.add(bt);

t.add(bt).row();
t.add(bt).fill().row();

bt.addListener(new ChangeListener() {
@Override
Expand Down Expand Up @@ -136,8 +137,11 @@ public void changed(ChangeEvent event, Actor actor) {
cui.btLock = btLock;
}

Table menu = new Table(skin);
menu.defaults().pad(10).fill();

TextButton btTest = new TextButton("Play", skin);
root.add(btTest).row();
menu.add(btTest).row();
btTest.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Expand All @@ -146,7 +150,7 @@ public void changed(ChangeEvent event, Actor actor) {
});

TextButton btRand = new TextButton("Randomize", skin);
root.add(btRand).row();
menu.add(btRand).row();
btRand.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Expand All @@ -155,7 +159,7 @@ public void changed(ChangeEvent event, Actor actor) {
});

TextButton btLockAll = new TextButton("Lock All", skin);
root.add(btLockAll).row();
menu.add(btLockAll).row();
btLockAll.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Expand All @@ -165,7 +169,7 @@ public void changed(ChangeEvent event, Actor actor) {
}
});
TextButton btUnLockAll = new TextButton("Unlock All", skin);
root.add(btUnLockAll).row();
menu.add(btUnLockAll).row();
btUnLockAll.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Expand All @@ -176,7 +180,7 @@ public void changed(ChangeEvent event, Actor actor) {
});

TextButton btSavePreset = new TextButton("Save Preset", skin);
root.add(btSavePreset).row();
menu.add(btSavePreset).row();
btSavePreset.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Expand All @@ -185,7 +189,7 @@ public void changed(ChangeEvent event, Actor actor) {
});

TextButton btLoadPreset = new TextButton("Load Preset", skin);
root.add(btLoadPreset).row();
menu.add(btLoadPreset).row();
btLoadPreset.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
Expand All @@ -194,27 +198,29 @@ public void changed(ChangeEvent event, Actor actor) {
});

TextButton btExportAudio = new TextButton("Export Audio", skin);
root.add(btExportAudio).row();
menu.add(btExportAudio).row();
btExportAudio.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
exportAudio();
}
});

TextButton btUpdateForm = new TextButton("Update form", skin);
root.add(btUpdateForm).row();
btUpdateForm.addListener(new ChangeListener() {
menu.add(new Image(waveFormRenderer.getTexture())).row();
menu.add(new Image(finalWaveRenderer.getTexture())).row();

root.add(menu);
root.add(controlsTable);

loadPreset(Gdx.files.local(presetPath + "/bonus.txt"));

stage.addAction(Actions.sequence(Actions.delay(1), Actions.run(new Runnable() {
@Override
public void changed(ChangeEvent event, Actor actor) {
int size = Pd.audio.arraySize("wave");
float[] array = new float[size];
Pd.audio.readArray(array, 0, "wave", 0, size);
finalWaveRenderer.update(array);
public void run() {
requestWaveFormUpdate = true;
}
});
})));

root.add(controlsTable);
}

private void savePreset(FileHandle file) {
Expand All @@ -241,7 +247,7 @@ protected void loadPreset() {
Table presetList = new Table(skin);
presetList.defaults().fill().padRight(20).padLeft(20);

for(final FileHandle file : Gdx.files.local("../presets").list("txt")){
for(final FileHandle file : Gdx.files.local(presetPath).list("txt")){
TextButton btPreset = new TextButton(file.nameWithoutExtension(), skin);
presetList.add(btPreset).row();
btPreset.addListener(new ChangeListener() {
Expand Down Expand Up @@ -280,7 +286,7 @@ protected void result(Object object) {
String name = tf.getText().trim();
if(!name.isEmpty()){
lastPresetName = name;
savePreset(Gdx.files.local("../presets").child(name + ".txt"));
savePreset(Gdx.files.local(presetPath).child(name + ".txt"));
}
}
}
Expand All @@ -304,7 +310,7 @@ protected void result(Object object) {
tf.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField textField, char c) {
if(Gdx.files.local("../presets").child(textField.getText().trim() + ".txt").exists()){
if(Gdx.files.local(presetPath).child(textField.getText().trim() + ".txt").exists()){
lb.setVisible(true);
}else{
lb.setVisible(false);
Expand All @@ -324,7 +330,7 @@ protected void result(Object object) {
String name = tf.getText().trim();
if(!name.isEmpty()){
lastPresetName = name;
exportAudio(Gdx.files.local("../audio").child(name + ".wav"));
exportAudio(Gdx.files.local(audioPath).child(name + ".wav"));
}
}
}
Expand All @@ -348,7 +354,7 @@ protected void result(Object object) {
tf.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped(TextField textField, char c) {
if(Gdx.files.local("../audio").child(textField.getText().trim() + ".wav").exists()){
if(Gdx.files.local(audioPath).child(textField.getText().trim() + ".wav").exists()){
lb.setVisible(true);
}else{
lb.setVisible(false);
Expand Down Expand Up @@ -415,7 +421,6 @@ public void render(float delta) {
float[] array = new float[size];
Pd.audio.readArray(array, 0, "waveform", 0, size);
waveFormRenderer.update(array);
System.out.println("update WaveForm");
}

if(requestUpdate){
Expand All @@ -426,22 +431,11 @@ public void render(float delta) {
float[] array = new float[size];
Pd.audio.readArray(array, 0, "wave", 0, size);
finalWaveRenderer.update(array);
System.out.println("update");
}
}

Gdx.gl.glClearColor(0, 0, 0, 0);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
super.render(delta);

shapeRenderer.getTransformMatrix().idt();
shapeRenderer.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
shapeRenderer.updateMatrices();
finalWaveRenderer.draw(shapeRenderer);

shapeRenderer.getTransformMatrix().setToTranslation(0, 200, 0);
shapeRenderer.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
shapeRenderer.updateMatrices();
waveFormRenderer.draw(shapeRenderer);
}
}
24 changes: 22 additions & 2 deletions src/net/mgsx/pfxr/ui/WaveFormUI.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
package net.mgsx.pfxr.ui;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Pixmap.Format;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer.ShapeType;

public class WaveFormUI {
private float [] vertices;
private int width, height;
private FrameBuffer fbo;
private ShapeRenderer renderer;
private Color bgColor = new Color(Color.BLUE).mul(.3f);

public WaveFormUI(int width, int height) {
super();
this.width = width;
this.height = height;
vertices = new float[width * 2];
renderer = new ShapeRenderer();
renderer.getProjectionMatrix().setToOrtho2D(0, 0, width, height);
fbo = new FrameBuffer(Format.RGBA8888, width, height, false);
}

public void update(float [] data){
Expand All @@ -23,12 +34,21 @@ public void update(float [] data){
vertices[x * 2 + 0] = x;
vertices[x * 2 + 1] = y * height;
}
draw();
}

public void draw(ShapeRenderer renderer){
private void draw(){
fbo.begin();
Gdx.gl.glClearColor(bgColor.r, bgColor.g, bgColor.b, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
renderer.begin(ShapeType.Line);
renderer.setColor(Color.BLUE);
renderer.polyline(vertices, 0, vertices.length/2);
renderer.polyline(vertices, 0, vertices.length);
renderer.end();
fbo.end();
}

public Texture getTexture() {
return fbo.getColorBufferTexture();
}
}

0 comments on commit 2237816

Please sign in to comment.