File: ruby.hpp

package info (click to toggle)
higan 106-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, sid
  • size: 9,640 kB
  • sloc: cpp: 108,736; ansic: 809; makefile: 22; sh: 7
file content (117 lines) | stat: -rw-r--r-- 4,516 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
#pragma once

/* ruby
 * author: byuu
 * license: ISC
 * version: 0.16 (2017-07-08)
 *
 * ruby is a cross-platform hardware abstraction layer.
 * it provides a common interface to video, audio and input devices.
 */

#include <nall/nall.hpp>

namespace ruby {

struct Video {
  static auto create(const nall::string& driver = "") -> Video*;
  static auto optimalDriver() -> nall::string;
  static auto safestDriver() -> nall::string;
  static auto availableDrivers() -> nall::string_vector;

  struct Information {
  };

  virtual ~Video() = default;

  virtual auto ready() -> bool { return true; }
  virtual auto information() -> Information { return {}; }

  virtual auto exclusive() -> bool { return false; }
  virtual auto context() -> uintptr { return 0; }
  virtual auto blocking() -> bool { return false; }
  virtual auto depth() -> uint { return 24; }
  virtual auto smooth() -> bool { return false; }
  virtual auto shader() -> nall::string { return ""; }

  virtual auto setExclusive(bool exclusive) -> bool { return false; }
  virtual auto setContext(uintptr context) -> bool { return false; }
  virtual auto setBlocking(bool blocking) -> bool { return false; }
  virtual auto setDepth(uint depth) -> bool { return false; }
  virtual auto setSmooth(bool smooth) -> bool { return false; }
  virtual auto setShader(nall::string shader) -> bool { return false; }

  virtual auto clear() -> void {}
  virtual auto lock(uint32_t*& data, uint& pitch, uint width, uint height) -> bool { return false; }
  virtual auto unlock() -> void {}
  virtual auto output() -> void {}
};

struct Audio {
  static auto create(const nall::string& driver = "") -> Audio*;
  static auto optimalDriver() -> nall::string;
  static auto safestDriver() -> nall::string;
  static auto availableDrivers() -> nall::string_vector;

  virtual ~Audio() = default;

  virtual auto availableDevices() -> nall::string_vector { return {"Default"}; }
  virtual auto availableFrequencies() -> nall::vector<double> { return {44100.0}; }
  virtual auto availableLatencies() -> nall::vector<uint> { return {0}; }
  virtual auto availableChannels() -> nall::vector<uint> { return {2}; }

  virtual auto ready() -> bool { return true; }
  virtual auto exclusive() -> bool { return false; }
  virtual auto context() -> uintptr { return 0; }
  virtual auto device() -> nall::string { return "None"; }
  virtual auto blocking() -> bool { return false; }
  virtual auto channels() -> uint { return 2; }
  virtual auto frequency() -> double { return 48000.0; }
  virtual auto latency() -> uint { return 0; }

  virtual auto setExclusive(bool exclusive) -> bool { return false; }
  virtual auto setContext(uintptr context) -> bool { return false; }
  virtual auto setDevice(nall::string device) -> bool { return false; }
  virtual auto setBlocking(bool blocking) -> bool { return false; }
  virtual auto setChannels(uint channels) -> bool { return false; }
  virtual auto setFrequency(double frequency) -> bool { return false; }
  virtual auto setLatency(uint latency) -> bool { return false; }

  virtual auto clear() -> void {}
  virtual auto output(const double samples[]) -> void {}
};

struct Input {
  static auto create(const nall::string& driver = "") -> Input*;
  static auto optimalDriver() -> nall::string;
  static auto safestDriver() -> nall::string;
  static auto availableDrivers() -> nall::string_vector;

  struct Information {
  };

  virtual ~Input() = default;

  virtual auto ready() -> bool { return true; }
  virtual auto information() -> Information { return {}; }

  virtual auto context() -> uintptr { return 0; }

  virtual auto setContext(uintptr context) -> bool { return false; }

  virtual auto acquired() -> bool { return false; }
  virtual auto acquire() -> bool { return false; }
  virtual auto release() -> bool { return false; }
  virtual auto poll() -> nall::vector<nall::shared_pointer<nall::HID::Device>> { return {}; }
  virtual auto rumble(uint64_t id, bool enable) -> bool { return false; }

  auto onChange(const nall::function<void (nall::shared_pointer<nall::HID::Device>, uint, uint, int16_t, int16_t)>& callback) { _onChange = callback; }
  auto doChange(nall::shared_pointer<nall::HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue) -> void {
    if(_onChange) _onChange(device, group, input, oldValue, newValue);
  }

private:
  nall::function<void (nall::shared_pointer<nall::HID::Device> device, uint group, uint input, int16_t oldValue, int16_t newValue)> _onChange;
};

}