Files
Nonemm/bridge/XmmrControl.h
ericek111 54b9181c06 Let MMTTY hold the text waiting to go out, behind a setting
MMTTY has a type-ahead buffer of its own: characters go into it, a backspace
takes back one it has not transmitted, and TxBufLen says how many are left. Used
that way it paces itself, so there is no gap between characters to tune and no
baud rate to keep in step with the engine.

EngineTypeAhead does that, and Config > Digital picks between it and the pump
that is there now. Off is still the default: three things it rests on have never
been seen with a real engine.

tools/Nonemm.EngineProbe asks the engine those three questions and writes the
answers to a file. It starts MMTTY through the bridge, pushes a message, polls
TxBufLen while it goes out, backspaces over text that has and has not been
transmitted, and logs what came back on the receive side and when.

The bridge learns one verb for it: `buffer` reads TxBufLen and answers with the
count, or -1 when the control will not say. A property the control does not know
is a log line rather than an error, since it stops nothing.

TypeAhead and EngineTypeAhead share the TransmitBuffer interface, which is what
the digital window now works through, so the window does not know which one it
has.

docs/unfinished.md states what each buffer assumes and how to run the probe.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RtspmWmS7f8kUvcyaHpRWZ
2026-09-01 22:41:18 +00:00

57 lines
1.7 KiB
C++

#pragma once
#include <windows.h>
#include <ole2.h>
#include <ocidl.h>
#include <functional>
#include <string>
#include "ControlSite.h"
#include "EventSink.h"
// The XMMR control out of XMMT.ocx, which is what N1MM drives MMTTY and 2Tone
// with. The control starts the engine, and the engine reports back through the
// control's events.
class XmmrControl {
public:
using EventHandler = SinkHandler;
explicit XmmrControl(EventHandler handler) : handler_(std::move(handler)) {}
~XmmrControl() { destroy(); }
bool create(HWND parent, std::string* error);
void destroy();
HRESULT put(const wchar_t* name, VARIANT value);
HRESULT putBool(const wchar_t* name, bool value);
HRESULT putLong(const wchar_t* name, long value);
HRESULT putString(const wchar_t* name, const std::string& value);
HRESULT call(const wchar_t* name, VARIANT* arguments, unsigned count);
HRESULT callLong(const wchar_t* name, long first, long second);
long getLong(const wchar_t* name);
// The same, saying whether the control answered. A property that is not
// there returns DISP_E_UNKNOWNNAME, which is how a name can be checked.
HRESULT tryGetLong(const wchar_t* name, long* value);
std::string getString(const wchar_t* name);
private:
HRESULT invoke(const wchar_t* name, WORD flags, DISPPARAMS* arguments, VARIANT* result);
bool listen(std::string* error);
EventHandler handler_;
ControlSite* site_ = nullptr;
IOleObject* object_ = nullptr;
IDispatch* dispatch_ = nullptr;
IConnectionPoint* point_ = nullptr;
IUnknown* sink_ = nullptr;
DWORD cookie_ = 0;
};
std::string toUtf8(const wchar_t* text);
std::wstring toWide(const std::string& text);