-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzqloader.h
153 lines (112 loc) · 4.34 KB
/
zqloader.h
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//==============================================================================
// PROJECT: zqloader
// FILE: zqloader.h
// DESCRIPTION: Definition of class ZQLoader.
// This is the main ZQLoader interface used for both commandline
// as qt ui tool.
//
// Copyright (c) 2024 Daan Scherft [Oxidaan]
// This project uses the MIT license. See LICENSE.txt for details.
//==============================================================================
#pragma once
#include <memory> // std::unique_ptr
#include <functional>
#include <filesystem>
#include "types.h" // CompressionType
#ifdef _MSC_VER
#pragma warning(disable: 4251) // class '' needs to have dll-interface to be used by clients of class ''
// Build, dll
#if defined( LIB_BUILD )
#define LIB_API __declspec( dllexport )
//#pragma message( "Build, DLL")
#endif
// Use, dll
#if !defined( LIB_BUILD )
#define LIB_API __declspec( dllimport )
//#pragma message( "Use, DLL")
#endif
#else
#define LIB_API
#endif
struct DataBlock;
/// This is the main ZQLoader interface used for both commandline
/// as qt ui tool.
class LIB_API ZQLoader
{
public:
enum class Action
{
play_audio,
write_wav,
write_tzx,
};
using DoneFun = std::function<void(void)>;
public:
ZQLoader();
~ZQLoader();
/// Set path/to/file to normal speed load (tzx,tap)
/// When empty use (and find) zqloader.tap.
ZQLoader &SetNormalFilename(std::filesystem::path p_filename);
/// Set path/to/file to turboload (tzx,tap,z80,sna)
ZQLoader &SetTurboFilename(std::filesystem::path p_filename);
/// Set output file when action is write_wav or write_tzx.
ZQLoader &SetOutputFilename(std::filesystem::path p_filename, bool p_allow_overwrite);
/// Set Volume (-100 -- 100).
ZQLoader &SetVolume(int p_volume_left, int p_volume_right);
/// Set miniaudio sample rate. 0 = device default.
ZQLoader& SetSampleRate(uint32_t p_sample_rate);
/// Set zqloader duration parameters.
ZQLoader& SetBitLoopMax(int p_value);
/// Set zqloader duration parameters.
ZQLoader& SetBitOneThreshold(int p_value);
/// Set zqloader duration parameters.
ZQLoader& SetDurations(int p_zero_duration, int p_one_duration, int p_end_of_byte_delay);
/// Set compression used: none/rle/automatic.
ZQLoader& SetCompressionType(CompressionType p_compression_type);
/// What to do (on Run/Start):
/// Play sound/ or write wav file/ or write tzx file.
ZQLoader& SetAction(Action p_what);
/// When loading snapshot put loader at screen.
ZQLoader &SetUseScreen();
/// Address where to put loader when loading snapshot, 0 = auto.
ZQLoader &SetNewLoaderLocation(uint16_t p_address);
/// Overwrite loader when at screen with attributes?
ZQLoader &SetFunAttribs(bool p_value);
/// Reset, stop, wipe all added data (files)
ZQLoader& Reset();
// Start/wait/stop
ZQLoader& Run();
// Start threaded
ZQLoader& Start();
// Stop/abort sound thread
ZQLoader& Stop();
ZQLoader & WaitUntilDone();
/// Busy (playing sound)?
bool IsBusy() const;
ZQLoader &SetPreload();
bool IsPreLoaded() const;
/// Play a infinite leader tone for tuning.
ZQLoader &PlayleaderTone();
ZQLoader &AddDataBlock(DataBlock p_block, uint16_t p_start_address);
/// Time at end so actual time needed once done.
std::chrono::milliseconds GetTimeNeeded() const;
/// Current running/loading time so since start.
std::chrono::milliseconds GetCurrentTime() const;
/// Estimated time needed calculated before.
/// Note: this is not 100% accurate.
std::chrono::milliseconds GetEstimatedDuration() const;
/// path to current zqloader.exe (this program)
/// (only to help find zqloader.tap)
ZQLoader& SetExeFilename(std::filesystem::path p_filename);
/// Set callback when done.
ZQLoader& SetOnDone(DoneFun p_fun);
/// Get miniadio native device sample rate
int GetDeviceSampleRate() const;
/// Get path/to/zqloader.tap
std::filesystem::path GetZqLoaderFile() const;
void Test();
static bool WriteTextToAttr(DataBlock &out_attr, const std::string &p_text, std::byte p_color, bool p_center, int p_col);
private:
class Impl;
std::unique_ptr<Impl> m_pimpl;
};