root/branches/transport_redesign_2/libs/hydrogen/src/transport/H2Transport.cpp @ 1088

Revision 1088, 3.6 KB (checked in by gabriel@…, 4 years ago)

Change API for Jack Transport Master. Remove unused methods from H2Core::Hydrogen.

This is a partial changeover. The API is changed, but:

  • H2Transport.cpp does not compile because the EVENT_JACK_MASTER needs to be implemented for the Event Queue.
  • hydrogen.cpp still does not compile.
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 <memory>
24#include <hydrogen/event_queue.h>
25#include "H2Transport.h"
26#include "SimpleTransportMaster.h"
27#include "JackTimeMaster.h"
28
29using namespace H2Core;
30
31class H2Core::H2TransportPrivate
32{
33public:
34    std::auto_ptr<Transport> xport;
35
36    /* This is used as a heartbeat signal with the JACK transport.
37     * It always sets it true.  We always set it false.  If it's
38     * ever false, then we're no longer being called... and probably
39     * no longer the transport master.
40     */
41    bool presumed_jtm;  // We *think* we're the Jack time master.
42    bool heartbeat_jtm;
43    std::auto_ptr<JackTimeMaster> jtm;
44    Song* pSong;  // Cached pointer for JTM
45};
46
47H2Transport::H2Transport() :
48    d(0)   
49{
50    d = new H2TransportPrivate;
51    d->xport.reset( new SimpleTransportMaster );
52    d->presumed_jtm = false;
53    d->heartbeat_jtm = false;
54    d->pSong = 0;
55}
56
57H2Transport::~H2Transport()
58{
59    delete d;
60}
61
62int H2Transport::locate(uint32_t frame)
63{
64    if(d->xport.get()) return d->xport->locate(frame);
65    return -1;
66}
67
68int H2Transport::locate(uint32_t bar, uint32_t beat, uint32_t tick)
69{
70    if(d->xport.get()) return d->xport->locate(bar, beat, tick);
71    return -1;
72}
73
74void H2Transport::start(void)
75{
76    EventQueue::get_instance()->push_event( EVENT_TRANSPORT, (int)TransportPosition::ROLLING );
77    if(d->xport.get()) d->xport->start();
78}
79
80void H2Transport::stop(void)
81{
82    EventQueue::get_instance()->push_event( EVENT_TRANSPORT, (int)TransportPosition::STOPPED );
83    if(d->xport.get()) d->xport->stop();
84}
85
86void H2Transport::get_position(TransportPosition* pos)
87{
88    if(d->xport.get()) d->xport->get_position(pos);
89}
90
91void H2Transport::processed_frames(uint32_t nFrames)
92{
93    if( d->heartbeat_jtm == false && d->presumed_jtm == true ) {
94        EventQueue::get_instance()->push_event( EVENT_JACK_MASTER, JACK_MASTER_NO_MORE );
95        d->presumed_jtm = false;
96    }
97    d->heartbeat_jtm = false;
98
99    if(d->xport.get()) d->xport->processed_frames(nFrames);
100}
101
102void H2Transport::set_current_song(Song* s)
103{
104    d->pSong = s;
105    if( d->jtm.get() ) {
106        d->jtm->set_current_song(s);
107    }
108    if(d->xport.get()) d->xport->set_current_song(s);
109}
110
111uint32_t H2Transport::get_current_frame()
112{
113    if(d->xport.get()) {
114        return d->xport->get_current_frame();
115    }
116    return (uint32_t)-1;
117}
118
119TransportPosition::State H2Transport::get_state()
120{
121    if(d->xport.get()) {
122        return d->xport->get_state();
123    }
124    return TransportPosition::STOPPED;
125}
126
127bool H2Transport::setJackTimeMaster(bool if_none_already)
128{
129    if( ! d->jtm.get() ) {
130        d->jtm.reset( new JackTimeMaster );
131        d->jtm->set_current_song( d->pSong );
132    }
133    return d->jtm->setMaster(if_none_already);
134}
135
136void H2Transport::clearJackTimeMaster()
137{
138    if( d->jtm.get() ) {
139        d->jtm->clearMaster();
140    }
141}
142
143bool H2Transport::getJackTimeMaster()
144{
145    return d->presumed_jtm;
146}
Note: See TracBrowser for help on using the browser.