Real Time Open Sound Control librtosc: /build/rtosc/src/rtosc-0.3.1/include/rtosc/savefile.h Source File

Real Time Open Sound Control librtosc

Loading...
Searching...
No Matches
savefile.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Johannes Lorenz
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
32#ifndef RTOSC_SAVEFILE
33#define RTOSC_SAVEFILE
34
35#include <string>
36#include <rtosc/rtosc.h>
37#include <rtosc/rtosc-version.h>
38
39namespace rtosc {
40
54std::string get_changed_values(const struct Ports& ports, void* runtime);
55
59 class savefile_dispatcher_t
60{
61 const struct Ports* ports;
62 void* runtime;
63 char loc[1024];
64
65protected:
66 enum proceed {
67 abort = -2,
68 discard = -1
69 };
70
71 enum dependency_t {
72 no_dependencies,
73 has_dependencies,
74 not_specified
75 };
76
77 rtosc_version rtosc_filever,
78 rtosc_curver,
79 app_filever,
80 app_curver;
81
83 bool operator()(const char* msg) { return do_dispatch(msg); }
84
85 static int default_response(size_t nargs, bool first_round,
86 dependency_t dependency);
87
88private:
91 virtual int on_dispatch(size_t portname_max, char* portname,
92 size_t maxargs, size_t nargs,
93 rtosc_arg_val_t* args,
94 bool round2, dependency_t dependency);
96 virtual bool do_dispatch(const char* msg);
97
98 friend int dispatch_printed_messages(const char* messages,
99 const struct Ports& ports,
100 void* runtime,
101 savefile_dispatcher_t *dispatcher);
102
103 friend int load_from_file(const char* file_content,
104 const struct Ports& ports, void* runtime,
105 const char* appname,
106 rtosc_version appver,
107 savefile_dispatcher_t* dispatcher);
108};
109
122 int dispatch_printed_messages(const char* messages,
123 const struct Ports& ports, void* runtime,
124 savefile_dispatcher_t *dispatcher = NULL);
125
136std::string save_to_file(const struct Ports& ports, void* runtime,
137 const char* appname, rtosc_version appver,
138 std::string file_str = "");
139
152 int load_from_file(const char* file_content,
153 const struct Ports& ports, void* runtime,
154 const char* appname,
155 rtosc_version appver,
156 savefile_dispatcher_t* dispatcher = NULL);
157
158}
159
160#endif // RTOSC_SAVEFILE
rtosc::savefile_dispatcher_t
Class to modify and dispatch messages loaded from savefiles.
Definition savefile.h:60
rtosc::savefile_dispatcher_t::dispatch_printed_messages
friend int dispatch_printed_messages(const char *messages, const struct Ports &ports, void *runtime, savefile_dispatcher_t *dispatcher)
Scan OSC messages from human readable format and dispatch them.
rtosc::savefile_dispatcher_t::proceed
proceed
Definition savefile.h:66
rtosc::savefile_dispatcher_t::abort
@ abort
the message shall lead to abort the savefile loading
Definition savefile.h:67
rtosc::savefile_dispatcher_t::discard
@ discard
the message shall not be dispatched
Definition savefile.h:68
rtosc::savefile_dispatcher_t::app_filever
rtosc_version app_filever
app version savefile was written with
Definition savefile.h:79
rtosc::savefile_dispatcher_t::app_curver
rtosc_version app_curver
current app version
Definition savefile.h:80
rtosc::savefile_dispatcher_t::rtosc_filever
rtosc_version rtosc_filever
rtosc versinon savefile was written with
Definition savefile.h:77
rtosc::savefile_dispatcher_t::dependency_t
dependency_t
Definition savefile.h:71
rtosc::savefile_dispatcher_t::not_specified
@ not_specified
default values do depend on others
Definition savefile.h:74
rtosc::savefile_dispatcher_t::has_dependencies
@ has_dependencies
default values don't depend on others
Definition savefile.h:73
rtosc::savefile_dispatcher_t::operator()
bool operator()(const char *msg)
call this to dispatch a message
Definition savefile.h:83
rtosc::savefile_dispatcher_t::rtosc_curver
rtosc_version rtosc_curver
rtosc version of this library
Definition savefile.h:78
rtosc::savefile_dispatcher_t::load_from_file
friend int load_from_file(const char *file_content, const struct Ports &ports, void *runtime, const char *appname, rtosc_version appver, savefile_dispatcher_t *dispatcher)
Read save file and dispatch contained parameters.
rtosc-version.h
Definition of rtosc's version struct.
rtosc.h
Functions handling messages and arguments.
rtosc::get_changed_values
std::string get_changed_values(const struct Ports &ports, void *runtime)
Return a string list of all changed values.
rtosc::save_to_file
std::string save_to_file(const struct Ports &ports, void *runtime, const char *appname, rtosc_version appver, std::string file_str="")
Return a savefile containing all values that differ from the default values.
rtosc::dispatch_printed_messages
int dispatch_printed_messages(const char *messages, const struct Ports &ports, void *runtime, savefile_dispatcher_t *dispatcher=NULL)
Scan OSC messages from human readable format and dispatch them.
rtosc::load_from_file
int load_from_file(const char *file_content, const struct Ports &ports, void *runtime, const char *appname, rtosc_version appver, savefile_dispatcher_t *dispatcher=NULL)
Read save file and dispatch contained parameters.
rtosc::Ports
Ports - a dispatchable collection of Port entries.
Definition ports.h:159
rtosc_arg_val_t
Definition rtosc.h:86
rtosc_version
struct containing an rtosc version
Definition rtosc-version.h:42