root/branches/transport_redesign_2/test/t_SimpleTransportMaster.cpp @ 1151

Revision 1151, 4.6 KB (checked in by gabriel@…, 4 years ago)

Add tests and some fixes to SimpleTransportMaster?.

* Modified behavior of normalize() to *NOT* adjust

the frame. After further thought, this was the
wrong thing to do.

* Change SimpleTransportMaster::processed_frames() to

calculate more stabily... but this is still some
scaffolding code to get things going.

* add a TransportPosition::normalize(target_frame)

method to do a normalization, but also make sure that
we end up on the specified beat.

Status: Hydrogen will scroll when you press play, but still no audio
output. Also, the GUI seems to be off-by-one when it comes to bars
and beats. Fails on a vector bounds check in the GUI thread.

Also, The new tests have some tests that fail even though things are
working as expected. Need to go in and fix up those tests.

Line 
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 *
5 * http://www.hydrogen-music.org
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY, without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20 *
21 */
22
23#include <transport/SimpleTransportMaster.h>
24#include <transport/songhelpers.h>
25#include <hydrogen/Song.h>
26#include <hydrogen/TransportPosition.h>
27
28#include <stdint.h>  // uint32_t, etc.
29
30// CHANGE THIS TO MATCH YOUR FILE:
31#define THIS_NAMESPACE t_SimpleTransportMaster
32#include "test_macros.h"
33
34using namespace H2Core;
35
36namespace THIS_NAMESPACE
37{
38
39    struct Fixture
40    {
41        Song* s;
42        SimpleTransportMaster x;
43
44        Fixture() {
45            s = Song::load( "test/t_SimpleTransportMaster.h2song" );
46            x.set_current_song(s);
47        }
48        ~Fixture() {
49            x.set_current_song(0);
50            delete s;
51        }
52    };
53
54#define VALID_POS(p, s) {                                                       \
55    BOOST_REQUIRE( typeid(p) == typeid(H2Core::TransportPosition) );    \
56    BOOST_REQUIRE( typeid(s) == typeid(H2Core::Song*) );                \
57    CK( (p).bar > 0 );                                                  \
58    CK( (p).bar <= song_bar_count(s) );                                 \
59    CK( (p).ticks_per_beat == 48 );                                     \
60    CK( (p).beats_per_bar == (ticks_in_bar((s),(p).bar)/48) );          \
61    CK( (p).beat_type == 4 );                                           \
62    CK( (p).beat > 0 );                                                 \
63    CK( (p).beat <= (p).beats_per_bar );                                \
64    CK( (p).tick < ticks_in_bar((s), (p).bar) );                        \
65    CK( (p).bbt_offset < (p).frames_per_tick() );                       \
66    CK( (p).bar_start_tick < song_tick_count(s) );                      \
67    CK( (p).bar_start_tick == bar_start_tick((s), (p).bar) );           \
68    CK( ((p).bar_start_tick + (p).tick) < song_tick_count(s) );         \
69}
70
71
72} // namespace THIS_NAMESPACE
73
74TEST_BEGIN( Fixture );
75
76TEST_CASE( 010_defaults )
77{
78    TransportPosition pos;
79
80    CK( x.get_state() == TransportPosition::STOPPED );
81    CK( 0 == x.get_current_frame() );
82    x.get_position(&pos);
83    VALID_POS(pos, s);
84    CK( pos.bar == 1 );
85    CK( pos.beat == 1 );
86    CK( pos.tick == 0 );
87    CK( pos.bar_start_tick == 0 );
88    CK( pos.frame == 0 );
89    CK( pos.bbt_offset == 0 );
90}
91
92void map_frame_to_bbt(uint32_t frame, uint32_t& bar, uint32_t& beat, uint32_t& tick, uint32_t& bbt_offset,
93                      uint32_t& bar_start_tick, double frames_per_tick)
94{
95    tick = floor( double(frame) / frames_per_tick );
96    bbt_offset = frame - round(double(tick) * frames_per_tick);
97    bar = (tick / 192) + 1;
98    bar_start_tick = (bar - 1) * 192;
99    tick = tick % 192;
100    beat = (tick / 48) + 1;
101    tick = tick % 48;
102}
103
104
105TEST_CASE( 020_start_stop )
106{
107    TransportPosition pos, posb;
108    x.get_position(&pos);
109    VALID_POS(pos, s);
110    x.processed_frames(1024);
111    x.get_position(&posb);
112    VALID_POS(posb, s);
113    CK( pos.frame == 0 );
114    CK( pos.bbt_offset == 0 );
115    CK( pos.frame == posb.frame );
116    CK( pos.bar == posb.bar );
117    CK( pos.beat == posb.beat );
118    CK( pos.tick == posb.tick );
119    CK( pos.bbt_offset == posb.bbt_offset );
120
121    CK( pos.frame_rate == 48000.0 );
122    uint32_t frame, delta = 1237;
123    uint32_t tot_frames = pos.frames_per_tick() * 192 * 8;
124    uint32_t tpbar = 192;  // ticks per bar
125    uint32_t bar, beat, tick, bbt_offset, __bar_start_tick;
126    uint32_t fpt, fpb;  // frames per tick, frames per bar
127    double tickdrift;
128
129    x.start();
130    for( frame = 0 ; frame <= tot_frames ; frame += delta ) {
131        x.get_position(&pos);
132        VALID_POS(pos, s);
133
134        CK( pos.beats_per_minute == 100.0 );
135        map_frame_to_bbt(frame, bar, beat, tick, bbt_offset, __bar_start_tick, pos.frames_per_tick());
136           
137        BOOST_MESSAGE("pos B:b.t.o @F = " << pos.bar << ":" << pos.beat << "."
138                      << pos.tick << "." << pos.bbt_offset << " @" << pos.frame);
139        BOOST_MESSAGE("cal B:b.t.o @F = " << bar << ":" << beat << "."
140                      << tick << "." << bbt_offset << " @" << frame);
141        CK( pos.frame == frame );
142        CK( pos.bar == bar );
143        CK( pos.beat == beat );
144        tickdrift = fabs(double(pos.tick) - double(tick));
145        if( tickdrift > (48.0/2.0) ) {
146            tickdrift -= pos.frames_per_tick();
147        }
148        CK( fabs(tickdrift) < 1.5 );
149        // This drifts to much to check:
150        // CK( pos.bbt_offset == bbt_offset );
151        CK( pos.bar_start_tick == __bar_start_tick );
152
153        x.processed_frames(delta);
154    }
155
156}
157
158TEST_END()
Note: See TracBrowser for help on using the browser.