File: sampleChannel.cpp

package info (click to toggle)
giada 0.16.2.2%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,080 kB
  • sloc: cpp: 35,706; sh: 1,056; makefile: 453; ansic: 1
file content (138 lines) | stat: -rw-r--r-- 2,858 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
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
40
41
42
43
44
45
46
47
48
49
50
51
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "../src/core/channels/sampleChannel.h"
#include "../src/core/model/model.h"
#include <catch.hpp>


TEST_CASE("sampleChannel")
{
	using namespace giada;
	using namespace giada::m;

	const int BUFFER_SIZE = 1024;
	const int WAVE_SIZE   = 50000;

	std::vector<ChannelMode> modes = { ChannelMode::LOOP_BASIC, 
		ChannelMode::LOOP_ONCE, ChannelMode::LOOP_REPEAT, 
		ChannelMode::LOOP_ONCE_BAR, ChannelMode::SINGLE_BASIC, 
		ChannelMode::SINGLE_PRESS, ChannelMode::SINGLE_RETRIG, 
		ChannelMode::SINGLE_ENDLESS };

	model::channels.clear();
	model::channels.push(std::make_unique<SampleChannel>(false, BUFFER_SIZE, 1, 1));

	model::onSwap(model::channels, 1, [&](Channel& c)
	{
		static_cast<SampleChannel&>(c).pushWave(1, WAVE_SIZE);
	});

	model::channels.lock();
	SampleChannel& ch = static_cast<SampleChannel&>(*model::channels.get(0));
	model::channels.unlock();

	SECTION("push wave")
	{
		REQUIRE(ch.playStatus == ChannelStatus::OFF);
		REQUIRE(ch.begin == 0);
		REQUIRE(ch.end == WAVE_SIZE);
		REQUIRE(ch.name == "");		
	}

	SECTION("begin/end")
	{
		/* TODO - This section requires model::waves interaction. Let's wait for 
		the non-virtual channel refactoring... */
		/*
		ch.setBegin(-100);

		REQUIRE(ch.getBegin() == 0);
		REQUIRE(ch.tracker == 0);
		REQUIRE(ch.trackerPreview == 0);

		ch.setBegin(100000);

		REQUIRE(ch.getBegin() == WAVE_SIZE);
		REQUIRE(ch.tracker == WAVE_SIZE);
		REQUIRE(ch.trackerPreview == WAVE_SIZE);

		ch.setBegin(16);

		REQUIRE(ch.getBegin() == 16);
		REQUIRE(ch.tracker == 16);
		REQUIRE(ch.trackerPreview == 16);

		ch.setEnd(0);

		REQUIRE(ch.getEnd() == 17);

		ch.setEnd(100000);

		REQUIRE(ch.getEnd() == WAVE_SIZE - 1);

		ch.setEnd(32);

		REQUIRE(ch.getEnd() == 32);

		ch.setBegin(64);

		REQUIRE(ch.getBegin() == 31);
		*/
	}

	SECTION("pitch")
	{
		ch.setPitch(40.0f);

		REQUIRE(ch.getPitch() == G_MAX_PITCH);

		ch.setPitch(-2.0f);

		REQUIRE(ch.getPitch() == G_MIN_PITCH);

		ch.setPitch(0.8f);

		REQUIRE(ch.getPitch() == 0.8f);
	}

	SECTION("position")
	{
		REQUIRE(ch.getPosition() == -1);  // Initially OFF

		ch.playStatus = ChannelStatus::PLAY;
		ch.tracker    = 1000;

		REQUIRE(ch.getPosition() == 1000);

		ch.begin = 700;

		REQUIRE(ch.getPosition() == 300);
	}

	SECTION("empty")
	{
		ch.empty();

		REQUIRE(ch.playStatus == ChannelStatus::EMPTY);
		REQUIRE(ch.begin == 0);
		REQUIRE(ch.end == 0);
		REQUIRE(ch.tracker == 0);
		REQUIRE(ch.volume == G_DEFAULT_VOL);
		REQUIRE(ch.hasActions == false);
		REQUIRE(ch.hasWave == false);
		REQUIRE(ch.waveId == 0);
	}

	SECTION("can record audio")
	{	
		REQUIRE(ch.canInputRec() == false); // Can't record if not armed

		ch.armed = true;

		REQUIRE(ch.canInputRec() == false); // Can't record with Wave in it

		ch.empty();

		REQUIRE(ch.canInputRec() == true);
	}

	/* TODO - fillBuffer, isAnyLoopMode, isAnySingleMode, isOnLastFrame */
}