Permalink
Browse files

Add basic support for Intan CLAMP files

  • Loading branch information...
neurodroid committed Mar 12, 2017
1 parent d9079fc commit 345d9521c86c83dd3642862aabde7cc6cf08368e
View
@@ -70,6 +70,9 @@ noinst_HEADERS = \
./src/libstfio/igor/igorlib.h \
./src/libstfio/igor/CrossPlatformFileIO.h \
./src/libstfio/igor/IgorBin.h \
+ ./src/libstfio/intan/common.h \
+ ./src/libstfio/intan/intanlib.h \
+ ./src/libstfio/intan/streams.h \
./src/libstfnum/stfnum.h ./src/libstfnum/fit.h ./src/libstfnum/spline.h \
./src/libstfnum/measure.h \
./src/libstfnum/levmar/lm.h ./src/libstfnum/levmar/levmar.h \
View
@@ -41,7 +41,10 @@ libstfio_la_SOURCES = ./channel.cpp ./section.cpp ./recording.cpp ./stfio.cpp \
./heka/hekalib.cpp \
./igor/igorlib.cpp \
./igor/CrossPlatformFileIO.c \
- ./igor/WriteWave.c
+ ./igor/WriteWave.c \
+ ./intan/common.cpp \
+ ./intan/intanlib.cpp \
+ ./intan/streams.cpp
if WITH_BIOSIG2
libstfio_la_SOURCES += ./biosig/biosiglib.cpp
@@ -0,0 +1,66 @@
+#include "common.h"
+#include <iostream>
+
+using std::ostream;
+using std::string;
+using std::wstring;
+
+class nullbuf : public std::streambuf
+{
+protected:
+ virtual int overflow(int c) { return c; }
+};
+
+class nullstream : public std::ostream {
+ nullbuf _streambuf;
+public:
+ nullstream() : std::ostream(&_streambuf)
+ {
+ clear();
+ }
+};
+
+// A stream that ouputs nowhere
+nullstream dev_null;
+
+ostream* logger = &dev_null;
+ostream* nulllogger = &dev_null;
+
+ostream* SetLogger(std::ostream* logger_) {
+ ostream* prev = logger;
+ if (logger_ == nullptr) {
+ logger = &dev_null;
+ }
+ else {
+ logger = logger_;
+ }
+ return prev;
+}
+
+wstring toWString(const string& s) {
+ wstring ws;
+ ws.insert(ws.begin(), s.begin(), s.end());
+ return ws;
+}
+
+string toString(const wstring& ws) {
+ string s;
+ s.insert(s.begin(), ws.begin(), ws.end());
+ return s;
+}
+
+#if defined WIN32 && defined _DEBUG
+bool _trace(TCHAR *format, ...)
+{
+ TCHAR buffer[1000];
+
+ va_list argptr;
+ va_start(argptr, format);
+ vswprintf_s(buffer, sizeof(buffer)/sizeof(buffer[0]), format, argptr);
+ va_end(argptr);
+
+ OutputDebugString(buffer);
+
+ return true;
+}
+#endif
@@ -0,0 +1,85 @@
+//----------------------------------------------------------------------------------
+// common.h
+//
+// Intan Technologies
+// Common Header File
+// Version 2.0 (25 August 2015)
+//
+// Provides common functionality for RHD and CLAMP source code.
+//
+// Copyright (c) 2014-2015 Intan Technologies LLC
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the
+// use of this software.
+//
+// Permission is granted to anyone to use this software for any applications that
+// use Intan Technologies integrated circuits, and to alter it and redistribute it
+// freely.
+//
+// See http://www.intantech.com for documentation and product information.
+//----------------------------------------------------------------------------------
+
+#pragma once
+
+#include <iosfwd>
+#include <string>
+#include <stdexcept>
+#include <sstream>
+
+using std::endl;
+
+// Debug output window printing macro
+#define DEBUGOUT( s ) \
+{ \
+ std::ostringstream os_; \
+ os_ << " DEBUG: " << s; \
+ OutputDebugStringA( os_.str().c_str() ); \
+}
+
+// Logging -----------------------------------------------------------------
+// Logging goes to this, which may point to dev_null
+extern std::ostream* logger;
+
+extern std::ostream* nulllogger; // Always points to dev_null
+
+// To
+#define LOG(x) ((x) ? (*logger) : (*nulllogger))
+
+// Use SetLogger(&std::cerr), for example, or SetLogger(nullptr).
+std::ostream* SetLogger(std::ostream* logger_);
+
+// _T macro for unicode support ---------------------------------------------
+#ifndef _T
+ #if defined(_WIN32) && defined(_UNICODE)
+ #define _T(x) L ##x
+ #else
+ #define _T(x) x
+ #endif
+#endif
+
+std::wstring toWString(const std::string& s);
+std::string toString(const std::wstring& ws);
+
+// Throws an exception if value has more than numBits set. For example, if you're trying to put something into 3 bits, and you specify 15.
+template <typename T>
+T CheckBits(T value, unsigned int numBits) {
+ T mask = (-1 << numBits);
+ if ((value & mask) != 0) {
+ throw std::invalid_argument("Invalid value with too many bits set.");
+ }
+ return value;
+}
+
+#define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
+
+#if defined WIN32
+ #define NOMINMAX
+ #include <windows.h>
+ bool _trace(TCHAR *format, ...);
+ #ifdef _DEBUG
+ #define TRACE _trace
+ #else
+ #define TRACE false && _trace
+ #endif
+#endif
Oops, something went wrong.

0 comments on commit 345d952

Please sign in to comment.