ClientPlayer.hpp 2.69 KB
Newer Older
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
#ifndef CLIENTPLAYER_HPP
#define CLIENTPLAYER_HPP

#include "ofSystemUtils.h"

#include "ofxCloudLib/CloudPlayerThread.hpp"

namespace ofxCloudLib
{

class ClientPlayer : public AbstractClient
{
  public:
    ClientPlayer(std::string client_name, int index) : AbstractClient(client_name, index){};

    void load_recording()
    {
        ofFileDialogResult result = ofSystemLoadDialog("load recording");
        if (result.bSuccess) {
            ofFile file = ofFile(result.getPath());
            cloud_player_.setup(file.getEnclosingDirectory());
            index_.setMax(cloud_player_.get_number_of_frames());
        }
    }

artificiel's avatar
artificiel committed
26
27
28
29
30
31
32
    void direct_load_recording(std::string path)
    {
        ofLogNotice("ClientPlayer") << "direct_load_recording: " << path;
        cloud_player_.setup(path);
        index_.setMax(cloud_player_.get_number_of_frames());
    }

33
34
35
36
37
38
39
40
41
    void control_playback(bool &b)
    {
        if (b) {
            cloud_player_.start();
        } else {
            cloud_player_.stop();
        }
    }

42
43
44
45
46
    void offset(float &b)
    {
        cloud_player_.offset_x_ = offset_x_;
        cloud_player_.offset_z_ = offset_z_;
    }
47

48
    ofMesh &get_mesh() override { return cloud_player_.get_mesh(); };
49
50
51

    void update() override
    {
52
53
54
55
56
        if (cloud_player_.isThreadRunning()) {
            cloud_player_.update_cloud();
            cloud_player_.update_mesh();
            index_.set(cloud_player_.get_current_frame());
        }
57
    }
58

59
60
    bool is_xyz_new() override { return playing_.get(); }

61
62
63
    void setup() override
    {
        AbstractClient::setup();
64
        gui_.add(recording_path_.setup("path", "/home/artificiel/recordings"));
65
66
67
68
        gui_.add(load_recording_.setup("load recording"));
        gui_.add(drawing_.set("drawing", 0));
        gui_.add(playing_.set("playing", 0));
        gui_.add(speed_.set("speed", 1, .1, 10));
artificiel's avatar
artificiel committed
69
        gui_.add(looping_.set("looping", false));
70
        gui_.add(index_.set("frame", 0, 0, 1000));
71
72
        gui_.add(offset_x_.set("offset x", 0, -10, 10));
        gui_.add(offset_z_.set("offset z", 0, -10, 10));
73
74
75

        load_recording_.addListener(this, &ClientPlayer::load_recording);
        playing_.addListener(this, &ClientPlayer::control_playback);
76
77
        offset_x_.addListener(this, &ClientPlayer::offset);
        offset_z_.addListener(this, &ClientPlayer::offset);
78
    }
79
80
81
82
83
84
85
86
87
88
89

    ofxTextField recording_path_;
    ofxButton load_recording_;
    ofParameter<float> speed_;
    ofParameter<bool> looping_;
    ofParameter<bool> playing_;
    ofParameter<float> offset_x_;
    ofParameter<float> offset_z_;
    ofParameter<bool> drawing_;
    ofParameter<int> index_;
    ofxCloudLib::CloudPlayerThread cloud_player_;
90
};
91
} // namespace ofxCloudLib
92
93

#endif // CLIENTPLAYER_HPP