Skip to content

Commit 3a3d9f0

Browse files
author
Rayerdyne
committed
Adding .gitignore and integrator filter
1 parent b6c02cf commit 3a3d9f0

File tree

82 files changed

+154
-16
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+154
-16
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin/
2+
bin/**

bin/ApplyEcho.class

-1.37 KB
Binary file not shown.

bin/CompositeExample.class

-1.84 KB
Binary file not shown.

bin/Demo.class

-2.06 KB
Binary file not shown.

bin/DummyFilter.class

-765 Bytes
Binary file not shown.

bin/Example.class

-2.3 KB
Binary file not shown.

bin/Test.class

-1.54 KB
Binary file not shown.

bin/Unrelated$1.class

-794 Bytes
Binary file not shown.

bin/Unrelated.class

-4.37 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-7.33 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-1.76 KB
Binary file not shown.
-597 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
-1.09 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-299 Bytes
Binary file not shown.
-245 Bytes
Binary file not shown.
-946 Bytes
Binary file not shown.
-1.88 KB
Binary file not shown.
-4.88 KB
Binary file not shown.
-2.03 KB
Binary file not shown.
Binary file not shown.
-7.25 KB
Binary file not shown.
-287 Bytes
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
-1.97 KB
Binary file not shown.
-1.91 KB
Binary file not shown.
-2.35 KB
Binary file not shown.
-1.68 KB
Binary file not shown.
Binary file not shown.
-4.46 KB
Binary file not shown.
Binary file not shown.
-6.81 KB
Binary file not shown.
-2.91 KB
Binary file not shown.
-1.61 KB
Binary file not shown.
-160 Bytes
Binary file not shown.
-2.93 KB
Binary file not shown.
-144 Bytes
Binary file not shown.
Binary file not shown.
-1.24 KB
Binary file not shown.
-1.01 KB
Binary file not shown.
-4.99 KB
Binary file not shown.
-382 Bytes
Binary file not shown.
-4.02 KB
Binary file not shown.
-632 Bytes
Binary file not shown.
-22.7 KB
Binary file not shown.
-15.2 KB
Binary file not shown.
Binary file not shown.
-8.83 KB
Binary file not shown.
Binary file not shown.
-10.9 KB
Binary file not shown.
-2.05 KB
Binary file not shown.
-6.27 KB
Binary file not shown.
Binary file not shown.

src/be/uliege/straet/oop/filters/IntegratorFilter.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
public class IntegratorFilter implements FeedbackableFilter {
1717

18+
public static final double DEF_SAMPLING_FREQUENCY = 44100.0;
19+
1820
private double integral;
1921
private double fs;
2022

@@ -31,7 +33,7 @@ public IntegratorFilter (double fs) {
3133
* Constructor, uses default sampling frequency 44100 Hz
3234
*/
3335
public IntegratorFilter() {
34-
this(44100.0);
36+
this(DEF_SAMPLING_FREQUENCY);
3537
}
3638

3739

@@ -76,4 +78,9 @@ public double[] incomingOutput() {
7678
public HashMap<String, String> getParameters() {
7779
return new HashMap<String, String>();
7880
}
81+
82+
/**
83+
* @return The sampling frequency, in Hz.
84+
*/
85+
public double getSamplingFrequency() { return fs; }
7986
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package be.uliege.straet.oop.gui;
2+
3+
import java.awt.Color;
4+
import java.awt.Graphics;
5+
6+
import be.uliege.straet.oop.filters.IntegratorFilter;
7+
8+
public class DIntegratorFilter extends DraggableFilter {
9+
10+
/** semi-height, actually */
11+
public static final int HEIGHT = 30;
12+
public static final int WIDTH = 20;
13+
14+
public static final int SYMBOL_HEIGHT = 20;
15+
public static final int SYMBOL_RADIUS = 8;
16+
17+
public DIntegratorFilter(int x, int y, WorkSpace ws, boolean selected,
18+
IntegratorFilter filter) {
19+
super(x, y, ws, selected);
20+
21+
xCorners = new int[4]; yCorners = new int[4];
22+
xCorners[0] = -WIDTH; yCorners[0] = -HEIGHT;
23+
xCorners[1] = WIDTH; yCorners[1] = -HEIGHT;
24+
xCorners[2] = WIDTH; yCorners[2] = HEIGHT;
25+
xCorners[3] = -WIDTH; yCorners[3] = HEIGHT;
26+
for (int i = 0; i < xCorners.length; i++) {
27+
xCorners[i] += x; yCorners[i] += y;
28+
}
29+
30+
inputs = new FixedBall[1];
31+
outputs = new FixedBall[1];
32+
inputs[0] = new FixedBall(x - WIDTH, y, true, this);
33+
outputs[0] = new FixedBall(x + WIDTH, y, false, this);
34+
35+
ws.addInputs(inputs);
36+
ws.addOutputs(outputs);
37+
38+
color = Color.WHITE;
39+
40+
filterR = filter;
41+
filterL = new IntegratorFilter(filter.getSamplingFrequency());
42+
parameterD = new double[] { IntegratorFilter.DEF_SAMPLING_FREQUENCY };
43+
parameterS = Double.toString(IntegratorFilter.DEF_SAMPLING_FREQUENCY);
44+
}
45+
46+
public DIntegratorFilter(int x, int y, WorkSpace ws, boolean selected) {
47+
this(x, y, ws, selected, new IntegratorFilter());
48+
}
49+
50+
@Override
51+
public int getParameterType() { return DraggableFilter.DOUBLE; }
52+
53+
@Override
54+
public String getParameterInfo()
55+
{ return "sampling frequency in Hz"; }
56+
57+
@Override
58+
public void paint(Graphics g, Color back, Color fore, double zoom) {
59+
super.paint(g, back, fore, zoom);
60+
g.drawPolygon(xCorners, yCorners, xCorners.length);
61+
int sh = WorkSpace.zoom(SYMBOL_HEIGHT, zoom);
62+
int sr = WorkSpace.zoom(SYMBOL_RADIUS, zoom);
63+
g.drawLine(x, y - sh, x, y + sh);
64+
g.drawArc(x, y - sh - sr/2, sr, sr, 0, 180);
65+
g.drawArc(x - sr, y + sh - sr/2, sr, sr, 180, 180);
66+
}
67+
68+
@Override
69+
public void setParameter(double[] d) {
70+
if (d.length > 1)
71+
return;
72+
parameterD = d;
73+
filterR = new IntegratorFilter(d[0]);
74+
filterL = new IntegratorFilter(d[0]);
75+
}
76+
}

src/be/uliege/straet/oop/gui/DraggableFilter.java

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ public void paint(Graphics g, Color back, Color fore, double zoom) {
227227
// painting of the parameters of the filter if there are some
228228
if (getParameterType() == NONE) return;
229229

230+
// painting filter's label
230231
g.setColor(Color.BLACK);
231232
String[] parts = parameterS.split("[/]");
232233
String toDraw = parts[parts.length - 1];

src/be/uliege/straet/oop/gui/README.md

+3-1

src/be/uliege/straet/oop/gui/Window.java

+37-14
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
import java.awt.Container;
66
import java.awt.event.ActionEvent;
77
import java.awt.event.ActionListener;
8-
import java.util.LinkedHashMap;
8+
import java.util.HashMap;
99

1010
import javax.swing.JFrame;
1111
import javax.swing.JPanel;
12+
import javax.swing.JComboBox;
1213

1314
import be.uliege.montefiore.oop.audio.FilterException;
1415

@@ -30,10 +31,12 @@ public class Window extends JFrame {
3031
/** It is a `LinkedHashMap` to be able to get the buttons in the order we
3132
* inserted them.
3233
*/
33-
private static LinkedHashMap<JButton, Procedure> buttonsActionsUp =
34-
new LinkedHashMap<JButton, Procedure>();
35-
private static LinkedHashMap<JButton, Procedure> buttonsActionsDown =
36-
new LinkedHashMap<JButton, Procedure>();
34+
private static HashMap<JButton, Procedure> buttonsActionsUp =
35+
new HashMap<JButton, Procedure>();
36+
private static HashMap<JButton, Procedure> buttonsActionsDown =
37+
new HashMap<JButton, Procedure>();
38+
String[] extraFilters = {"Composite", "Convolution", "Integrator"};
39+
JComboBox<String> filterComboBox = new JComboBox<String>(extraFilters);
3740

3841
public static void main(String[] args) {
3942
Window w = new Window(WINDOW_NAME);
@@ -52,14 +55,12 @@ public Window(String name) {
5255
catch (FilterException e) {
5356
System.out.println(e.getMessage());
5457
} });
55-
buttonsActionsUp.put(new JButton("Addition"), () -> {ws.addAddition();});
56-
buttonsActionsUp.put(new JButton("Delay"), () -> {ws.addDelay();});
57-
buttonsActionsUp.put(new JButton("Gain"), () -> {ws.addGain();});
58-
buttonsActionsUp.put(new JButton("Composite"), () -> {
59-
try { ws.addComposite(); }
60-
catch (Exception e) {
61-
WorkSpace.showError("Could not add the composite filter", e);
62-
} });
58+
buttonsActionsUp.put(new JButton("Delay"), () -> {ws.addDelay();});
59+
buttonsActionsUp.put(new JButton("Gain"), () -> {ws.addGain();});
60+
buttonsActionsUp.put(new JButton("Other: "), () -> {
61+
addSelectedFilter();
62+
});
63+
buttonsActionsUp.put(new JButton("Addition"), () -> {ws.addAddition();});
6364

6465
buttonsActionsDown.put(new JButton("Variable"),
6566
() -> {ws.addVariableDeclaration();});
@@ -71,7 +72,28 @@ public Window(String name) {
7172
new Thread(new RetardatorFocusGiver(ws)).start();
7273
}
7374

74-
private void initUi() {
75+
private void addSelectedFilter() {
76+
String filterType = (String) filterComboBox.getSelectedItem();
77+
switch (filterType) {
78+
case "Composite":
79+
try {
80+
ws.addComposite();
81+
} catch (Exception e) {
82+
WorkSpace.showError("Could not add the composite filter", e);
83+
}
84+
break;
85+
case "Convolution":
86+
ws.addConvolution();
87+
break;
88+
case "Integrator":
89+
ws.addIntegrator();
90+
break;
91+
default:
92+
break;
93+
}
94+
}
95+
96+
private void initUi() {
7597

7698
JPanel buttonsPanelUp = new JPanel();
7799
JPanel buttonsPanelDown = new JPanel();
@@ -96,6 +118,7 @@ public void actionPerformed(ActionEvent e) {
96118
buttonsPanelUp.add(b);
97119
b.addActionListener(bal);
98120
}
121+
buttonsPanelUp.add(filterComboBox);
99122
for (JButton b : buttonsActionsDown.keySet()) {
100123
buttonsPanelDown.add(b);
101124
b.addActionListener(bal);

src/be/uliege/straet/oop/gui/WorkSpace.java

+27
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import be.uliege.straet.oop.filters.ConvolutionFilter;
2626
import be.uliege.straet.oop.filters.DelayFilter;
2727
import be.uliege.straet.oop.filters.GainFilter;
28+
import be.uliege.straet.oop.filters.IntegratorFilter;
2829
import be.uliege.straet.oop.filters.WFilter;
2930
import be.uliege.straet.oop.loader.LoaderException;
3031
import be.uliege.straet.oop.loader.Writer;
@@ -406,6 +407,32 @@ public DraggableFilter addComposite(int x, int y, int orientation,
406407
filters.add(df);
407408
return df;
408409
}
410+
411+
/**
412+
* Starts the placing of a integrator filter.
413+
* @param x The x coordinate of the filter
414+
* @param y The y coordinate of the filter
415+
* @param orientation The orientation of the filter: the filter is oriented
416+
* "normally" + orientation * 90° clockwise.
417+
* @param selected Wether or not the user is dragging this filter when
418+
* it is placed.
419+
* @param filter An `Integrator` that will be used in that
420+
* `DIntegratorFilter`
421+
*/
422+
public DraggableFilter addIntegrator(int x, int y, int orientation,
423+
boolean selected, IntegratorFilter filter) {
424+
DIntegratorFilter df = new DIntegratorFilter(x, y, this, selected, filter);
425+
filters.add(df);
426+
return df;
427+
}
428+
429+
/** Starts the placing of a default integrator filter at (0, 0), needs
430+
* focus */
431+
public void addIntegrator() {
432+
if (isBusy()) return;
433+
addIntegrator(0, 0, 0, true, new IntegratorFilter());
434+
}
435+
409436
/**
410437
* Starts the placing of an input filter.
411438
* @param x The x coordinate of the filter

0 commit comments

Comments
 (0)