Fex

Check-in [1babdd1514]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:CamelCased function names in Spectrogram
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | origin/sfml
Files: files | file ages | folders
SHA3-256: 1babdd15142296bb3c98e94288434bac3dfede866c40cf730665c2bc1d9d406c
User & Date: jesse.mcclure@umassmed.edu 2016-02-17 18:40:43
Context
2016-02-17
18:45
remove accidental binary check-in: 1eac79ebc2 user: jesse.mcclure@umassmed.edu tags: trunk, origin/sfml
18:40
CamelCased function names in Spectrogram check-in: 1babdd1514 user: jesse.mcclure@umassmed.edu tags: trunk, origin/sfml
2016-02-16
14:37
SFML branch reached minimal functionality check-in: db9843bacb user: jesse.mcclure@umassmed.edu tags: trunk, origin/sfml
Changes

Changes to TODO.

1
2
3
4
5
6
7
8
9
10
11
12
13

- change function names to camelCase in spectrogram
x Add eraser function to spectrogram module
	- needs testing
- Add log transformation to frequency?
- Add cursorFG to config.cpp and python code
- Too many "magic numbers" for eraser sizes...
x Implement config file reading
	* offloaded to pyfex
	* fex only uses command line parameters
	* this makes porting across platforms easier
		* at least for me: I have no idea where a Win user would keep config files.


<











1

2
3
4
5
6
7
8
9
10
11
12


x Add eraser function to spectrogram module
	- needs testing
- Add log transformation to frequency?
- Add cursorFG to config.cpp and python code
- Too many "magic numbers" for eraser sizes...
x Implement config file reading
	* offloaded to pyfex
	* fex only uses command line parameters
	* this makes porting across platforms easier
		* at least for me: I have no idea where a Win user would keep config files.

Added fex.

cannot compute difference between binary files

Changes to src/fex.cpp.

1
2
3
4
5
6
7
8

#include "spectrogram.hpp"

int main(int argc, char *const *argv) {
	Spectrogram spec(argc, argv);
	spec.main_loop();
	return EXIT_SUCCESS;
}





|


1
2
3
4
5
6
7
8

#include "spectrogram.hpp"

int main(int argc, char *const *argv) {
	Spectrogram spec(argc, argv);
	spec.mainLoop();
	return EXIT_SUCCESS;
}

Changes to src/spectrogram.cpp.

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
	eraser.setFillColor(sf::Color(255,200,0,200));
	eraser.setPosition(0, 0);
	eraser.setOrigin(2, 10);
}

Spectrogram::~Spectrogram() { }

int Spectrogram::main_loop() {
	sf::Event ev;
	while (win.isOpen() && win.waitEvent(ev)) {
		ev_handler(ev);
		while (win.pollEvent(ev)) ev_handler(ev);
		draw_main();
		if (show.cursor) {
			if (crop1.x > 0) draw_cursor(crop1.x, crop1.y);
			draw_cursor(mouse.x, mouse.y);
		}
		win.display();
		char out[256];
		snprintf(out,255,"%s - (%0.3fs, %0.3fKHz) FE: %lf ",
			name,
			song.getDuration().asSeconds() * mouse.x / ntime,
			conf.lopass - (conf.hipass - conf.lopass) * mouse.y / nfreq,
................................................................................
		);
		win.setTitle(sf::String(out));
	}
	printf("%lf\t%lf\t%lf\n", pathLength, timeLength, pathLength / timeLength);
	return 0;
}

void Spectrogram::ev_handler(sf::Event ev) {
	switch (ev.type) {
		case sf::Event::Closed: ev_close(ev); break;
		case sf::Event::KeyPressed: ev_keypress(ev); break;
		case sf::Event::KeyReleased: ev_keyrelease(ev); break;
		case sf::Event::MouseMoved: ev_mousemove(ev); break;
		case sf::Event::MouseButtonPressed: ev_button(ev); break;
		case sf::Event::MouseWheelScrolled: ev_wheel(ev); break;
		case sf::Event::Resized: ev_resize(ev); break;
	}
}

void Spectrogram::draw_main() {
	win.clear(conf.winBG);
	win.draw(back);
	win.draw(spec);
	thresh.setColor(conf.threshFG);
	if (show.overlay) {
		win.draw(thresh);
		win.draw(getPoints(), &ball);
		win.draw(getLines());
		win.draw(eraser);
	}
}

void Spectrogram::draw_cursor(float x, float y) {
	// TODO get config cursor color
	sf::RectangleShape lineV(sf::Vector2f(1, nfreq));
	lineV.setFillColor(conf.cursorFG);
	lineV.setPosition(view.getViewport().left + x, -nfreq);
	win.draw(lineV);
	sf::RectangleShape lineH(sf::Vector2f(ntime, 1));
	lineH.setFillColor(conf.cursorFG);
................................................................................
	sf::Sound snd(song);
	snd.play();
	snd.setPitch(speed);
	while(snd.getStatus() == 2) {
		sf::RectangleShape line(sf::Vector2f(10, nfreq));
		line.setFillColor(sf::Color(0,255,0,120));
		line.setPosition(ntime * (snd.getPlayingOffset() / song.getDuration()), -nfreq);
		draw_main();
		win.draw(line);
		win.display();
	}
}

void Spectrogram::ev_close(sf::Event ev) {
}

void Spectrogram::ev_keypress(sf::Event ev) {
	if (ev.key.code == sf::Keyboard::LShift) show.cursor = true;
	if (ev.key.code == sf::Keyboard::RShift) show.cursor = true;
	if (ev.key.control) {
		if (ev.key.code == sf::Keyboard::Q) win.close();
		else if (ev.key.code == sf::Keyboard::Right) { conf.floor -= 0.25; makeSpectrogram(); }
		else if (ev.key.code == sf::Keyboard::Left) { conf.floor += 0.25; makeSpectrogram(); }
		else if (ev.key.code == sf::Keyboard::Up) { conf.threshold -= 0.25;  /* redraw overlay */ }
................................................................................
		if (ev.key.code == sf::Keyboard::Num2) listen(0.5);
		if (ev.key.code == sf::Keyboard::Num3) listen(0.333);
		if (ev.key.code == sf::Keyboard::Num4) listen(0.25);
		if (ev.key.code == sf::Keyboard::Num5) listen(0.2);
	}
}

void Spectrogram::ev_keyrelease(sf::Event ev) {
	if (ev.key.code == sf::Keyboard::LShift) show.cursor = false;
	if (ev.key.code == sf::Keyboard::RShift) show.cursor = false;
}

void Spectrogram::ev_resize(sf::Event ev) {
	aspect = (ntime * win.getSize().y * conf.hop) / (float) (nfreq * win.getSize().x * conf.winlen);
}

void Spectrogram::ev_mousemove(sf::Event ev) {
		sf::Vector2f prev = mouse;
		mouse = win.mapPixelToCoords(sf::Vector2i(ev.mouseMove.x,ev.mouseMove.y));
	checkModKeys();
	if (mod_ctrl) {
	}
	else if (mod_shift) {
	}
................................................................................
			if (point.x > -0.25 && point.x < 4.25 && point.y > -0.25 && point.y < 18.25)
				erasePoint(i, -j);
		}
	}
	makeOverlay();
}

void Spectrogram::ev_button(sf::Event ev) {
	checkModKeys();
	sf::FloatRect rect;
	/* Control + button combinations are for working with the threshold: */
	if (mod_ctrl) switch (ev.mouseButton.button) {
	}
	/* Shift + button combinations are for working with the crop area: */
	else if (mod_shift) switch (ev.mouseButton.button) {
................................................................................
			break;
	}
	/* Alt + button combinations are for working with the eraser: */
	else if (mod_alt) switch (ev.mouseButton.button) {
		case sf::Mouse::Button::Left: erase(); break;
	}
	else switch (ev.mouseButton.button) {
		/* NOTE: left and right are handled in ev_mousemove */
		/* zoom to fit song to window */
		case sf::Mouse::Button::Middle:
			view.reset(sf::FloatRect(0, -nfreq * (1 + aspect)/2.0, ntime, nfreq * aspect));
			win.setView(view);
			break;
	}
}

void Spectrogram::ev_wheel(sf::Event ev) {
	checkModKeys();
	bool vert = (ev.mouseWheelScroll.wheel == 0);
	float dx = ev.mouseWheelScroll.delta;
	/* Control + wheel combinations are for working with the threshold: */
	if (mod_ctrl && vert) {
		// TODO: threshold up/down
	}







|


|
|
|

|
|







 







|

|
|
|
|
|
|
|



|












|







 







|





|


|







 







|




|



|







 







|







 







|








|







28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
..
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
..
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
...
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
...
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
	eraser.setFillColor(sf::Color(255,200,0,200));
	eraser.setPosition(0, 0);
	eraser.setOrigin(2, 10);
}

Spectrogram::~Spectrogram() { }

int Spectrogram::mainLoop() {
	sf::Event ev;
	while (win.isOpen() && win.waitEvent(ev)) {
		evHandler(ev);
		while (win.pollEvent(ev)) evHandler(ev);
		drawMain();
		if (show.cursor) {
			if (crop1.x > 0) drawCursor(crop1.x, crop1.y);
			drawCursor(mouse.x, mouse.y);
		}
		win.display();
		char out[256];
		snprintf(out,255,"%s - (%0.3fs, %0.3fKHz) FE: %lf ",
			name,
			song.getDuration().asSeconds() * mouse.x / ntime,
			conf.lopass - (conf.hipass - conf.lopass) * mouse.y / nfreq,
................................................................................
		);
		win.setTitle(sf::String(out));
	}
	printf("%lf\t%lf\t%lf\n", pathLength, timeLength, pathLength / timeLength);
	return 0;
}

void Spectrogram::evHandler(sf::Event ev) {
	switch (ev.type) {
		case sf::Event::Closed: evClose(ev); break;
		case sf::Event::KeyPressed: evKeyPress(ev); break;
		case sf::Event::KeyReleased: evKeyRelease(ev); break;
		case sf::Event::MouseMoved: evMouseMove(ev); break;
		case sf::Event::MouseButtonPressed: evMouseButton(ev); break;
		case sf::Event::MouseWheelScrolled: evMouseWheel(ev); break;
		case sf::Event::Resized: evResize(ev); break;
	}
}

void Spectrogram::drawMain() {
	win.clear(conf.winBG);
	win.draw(back);
	win.draw(spec);
	thresh.setColor(conf.threshFG);
	if (show.overlay) {
		win.draw(thresh);
		win.draw(getPoints(), &ball);
		win.draw(getLines());
		win.draw(eraser);
	}
}

void Spectrogram::drawCursor(float x, float y) {
	// TODO get config cursor color
	sf::RectangleShape lineV(sf::Vector2f(1, nfreq));
	lineV.setFillColor(conf.cursorFG);
	lineV.setPosition(view.getViewport().left + x, -nfreq);
	win.draw(lineV);
	sf::RectangleShape lineH(sf::Vector2f(ntime, 1));
	lineH.setFillColor(conf.cursorFG);
................................................................................
	sf::Sound snd(song);
	snd.play();
	snd.setPitch(speed);
	while(snd.getStatus() == 2) {
		sf::RectangleShape line(sf::Vector2f(10, nfreq));
		line.setFillColor(sf::Color(0,255,0,120));
		line.setPosition(ntime * (snd.getPlayingOffset() / song.getDuration()), -nfreq);
		drawMain();
		win.draw(line);
		win.display();
	}
}

void Spectrogram::evClose(sf::Event ev) {
}

void Spectrogram::evKeyPress(sf::Event ev) {
	if (ev.key.code == sf::Keyboard::LShift) show.cursor = true;
	if (ev.key.code == sf::Keyboard::RShift) show.cursor = true;
	if (ev.key.control) {
		if (ev.key.code == sf::Keyboard::Q) win.close();
		else if (ev.key.code == sf::Keyboard::Right) { conf.floor -= 0.25; makeSpectrogram(); }
		else if (ev.key.code == sf::Keyboard::Left) { conf.floor += 0.25; makeSpectrogram(); }
		else if (ev.key.code == sf::Keyboard::Up) { conf.threshold -= 0.25;  /* redraw overlay */ }
................................................................................
		if (ev.key.code == sf::Keyboard::Num2) listen(0.5);
		if (ev.key.code == sf::Keyboard::Num3) listen(0.333);
		if (ev.key.code == sf::Keyboard::Num4) listen(0.25);
		if (ev.key.code == sf::Keyboard::Num5) listen(0.2);
	}
}

void Spectrogram::evKeyRelease(sf::Event ev) {
	if (ev.key.code == sf::Keyboard::LShift) show.cursor = false;
	if (ev.key.code == sf::Keyboard::RShift) show.cursor = false;
}

void Spectrogram::evResize(sf::Event ev) {
	aspect = (ntime * win.getSize().y * conf.hop) / (float) (nfreq * win.getSize().x * conf.winlen);
}

void Spectrogram::evMouseMove(sf::Event ev) {
		sf::Vector2f prev = mouse;
		mouse = win.mapPixelToCoords(sf::Vector2i(ev.mouseMove.x,ev.mouseMove.y));
	checkModKeys();
	if (mod_ctrl) {
	}
	else if (mod_shift) {
	}
................................................................................
			if (point.x > -0.25 && point.x < 4.25 && point.y > -0.25 && point.y < 18.25)
				erasePoint(i, -j);
		}
	}
	makeOverlay();
}

void Spectrogram::evMouseButton(sf::Event ev) {
	checkModKeys();
	sf::FloatRect rect;
	/* Control + button combinations are for working with the threshold: */
	if (mod_ctrl) switch (ev.mouseButton.button) {
	}
	/* Shift + button combinations are for working with the crop area: */
	else if (mod_shift) switch (ev.mouseButton.button) {
................................................................................
			break;
	}
	/* Alt + button combinations are for working with the eraser: */
	else if (mod_alt) switch (ev.mouseButton.button) {
		case sf::Mouse::Button::Left: erase(); break;
	}
	else switch (ev.mouseButton.button) {
		/* NOTE: left and right are handled in evMouseMove */
		/* zoom to fit song to window */
		case sf::Mouse::Button::Middle:
			view.reset(sf::FloatRect(0, -nfreq * (1 + aspect)/2.0, ntime, nfreq * aspect));
			win.setView(view);
			break;
	}
}

void Spectrogram::evMouseWheel(sf::Event ev) {
	checkModKeys();
	bool vert = (ev.mouseWheelScroll.wheel == 0);
	float dx = ev.mouseWheelScroll.delta;
	/* Control + wheel combinations are for working with the threshold: */
	if (mod_ctrl && vert) {
		// TODO: threshold up/down
	}

Changes to src/spectrogram.hpp.

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
		sf::Vector2f mouse, crop1;
		sf::RectangleShape back;
		sf::Texture ball;
		sf::RectangleShape eraser;
		bool mod_ctrl, mod_shift, mod_alt;
		float aspect;

		void draw_main();
		void draw_cursor(float, float);
		void draw_hud();
		void erase();

		void checkModKeys();
		void ev_handler(sf::Event);
		void ev_close(sf::Event);
		void ev_keypress(sf::Event);
		void ev_keyrelease(sf::Event);
		void ev_mousemove(sf::Event);
		void ev_resize(sf::Event);
		void ev_button(sf::Event);
		void ev_wheel(sf::Event);
	protected:
		void listen(float=1.0);
	public:
		int main_loop();
		Spectrogram(int, char *const *);
		~Spectrogram();
};








|
|
|



|
|
|
|
|
|
|
|



|




11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
		sf::Vector2f mouse, crop1;
		sf::RectangleShape back;
		sf::Texture ball;
		sf::RectangleShape eraser;
		bool mod_ctrl, mod_shift, mod_alt;
		float aspect;

		void drawMain();
		void drawCursor(float, float);
		void drawHud();
		void erase();

		void checkModKeys();
		void evHandler(sf::Event);
		void evClose(sf::Event);
		void evKeyPress(sf::Event);
		void evKeyRelease(sf::Event);
		void evMouseButton(sf::Event);
		void evMouseMove(sf::Event);
		void evMouseWheel(sf::Event);
		void evResize(sf::Event);
	protected:
		void listen(float=1.0);
	public:
		int mainLoop();
		Spectrogram(int, char *const *);
		~Spectrogram();
};