Skip to content

Commit

Permalink
Initial commit of sources
Browse files Browse the repository at this point in the history
  • Loading branch information
user authored and user committed Apr 27, 2017
1 parent 2aab5f8 commit 54d3bb1
Show file tree
Hide file tree
Showing 56 changed files with 8,048 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .dep.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This code depends on make tool being used
DEPFILES=$(wildcard $(addsuffix .d, ${OBJECTFILES} ${TESTOBJECTFILES}))
ifneq (${DEPFILES},)
include ${DEPFILES}
endif
88 changes: 88 additions & 0 deletions About.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2017 Kai Niessen <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* File: About.cpp
* Author: Kai Niessen <[email protected]>
*
* Created on March 20, 2017, 4:11 PM
*/

#include <TranslationUtils.h>
#include <Bitmap.h>
#include <StringView.h>
#include <Application.h>
#include <Roster.h>
#include <AppFileInfo.h>
#include <Resources.h>
#include <Archivable.h>
#include "RadioApp.h"
#include "About.h"
#include "Utils.h"

About::About()
: BWindow(BRect(0, 0, 180, 50), "About", B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE)
{
BRect bounds = Bounds();
BStringView* versionView = new BStringView(bounds, "versionView", GetAppVersion(), B_FOLLOW_LEFT_RIGHT | B_FOLLOW_BOTTOM);
AddChild(versionView);
versionView->SetDrawingMode(B_OP_COPY);
versionView->SetViewColor(238, 238, 235, 255);
versionView->SetHighColor(134, 135, 138, 255);
versionView->SetLowColor(134, 135, 138, 0);
BBitmap* banner = Utils::ResourceBitmap(RES_BANNER);
if (banner) {
bounds = banner->Bounds();
ResizeTo(bounds.Width(), bounds.Height() + versionView->PreferredSize().height);
versionView->SetFontSize(11);
versionView->SetAlignment(B_ALIGN_RIGHT);
versionView->ResizeTo(bounds.Width(), versionView->PreferredSize().height + 2);
versionView->MoveTo(0, bounds.Height());
BView* bannerView = new BView(bounds, "bannerView", B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_WILL_DRAW);
AddChild(bannerView, versionView);
bannerView->SetViewBitmap(banner, B_FOLLOW_ALL_SIDES);
} else {
versionView->SetFontSize(40);
versionView->SetAlignment(B_ALIGN_CENTER);
BSize preferredSize = versionView->PreferredSize();
ResizeTo(preferredSize.width + 10, preferredSize.height);
}
CenterOnScreen();
}

About::~About() {
}

BString About::GetAppVersion() {
BString versionString;
app_info appInfo;
version_info versionInfo;
BAppFileInfo appFileInfo;
BFile appFile;

if (be_app->GetAppInfo(&appInfo) == B_OK &&
appFile.SetTo(&appInfo.ref, B_READ_ONLY) == B_OK &&
appFile.InitCheck() == B_OK &&
appFileInfo.SetTo(&appFile) == B_OK &&
appFileInfo.GetVersionInfo(&versionInfo, B_APP_VERSION_KIND) == B_OK) {
versionString.SetTo(versionInfo.long_info);
} else {
versionString = "©Fishpond 2012-2017";
}
return versionString;
}

42 changes: 42 additions & 0 deletions About.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright (C) 2017 Kai Niessen <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* File: About.h
* Author: Kai Niessen <[email protected]>
*
* Created on March 20, 2017, 4:11 PM
*/

#ifndef ABOUT_H
#define ABOUT_H

#include <Window.h>
#include <String.h>

#define BANNER 4

class About : public BWindow {
public:
About();
virtual ~About();
private:
static BString GetAppVersion();
};

#endif /* ABOUT_H */

207 changes: 207 additions & 0 deletions Buffering.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
/*
* File: Buffering.h
* Author: Kai Niessen
*
* Created on January 31, 2016, 4:15 PM
*/

#ifndef BUFFERING_H
#define BUFFERING_H

/**
* Simple class extending an integer to roll over when reaching boundaries
*/
class rotor {
public:
rotor(int size, int initialValue = 0) {
fMax = size-1;
fValue = initialValue;
}
rotor(rotor& other) {
fMax = other.fMax;
fValue = other.fValue;
}
operator int() { return fValue; }
rotor& operator ++() { if (fValue==fMax) fValue=0; else fValue++; return *this;}
rotor& operator ++(int) { rotor* tmp=new rotor(*this); if (fValue==fMax) fValue=0; else fValue++; return *tmp;}
rotor& operator --() { if (fValue==0) fValue=fMax; else fValue--; return *this;}
rotor& operator --(int) { rotor* tmp=new rotor(*this); if (fValue==0) fValue=fMax; else fValue--; return *tmp;}
rotor& operator =(int i) { fValue = i % (fMax+1);}
int operator =(rotor& r) { return r.fValue;}
int operator -(rotor& other) {return (fValue-other.fValue + fMax + 1) % (fMax + 1);}
bool operator ==(int i) { return fValue==i;}
bool operator !=(int i) { return fValue!=i;}
bool operator <(int i) { return fValue<i;}
bool operator >(int i) { return fValue>i;}
private:
inline void setValue(int i) { fValue = i; }
inline int getValue() { return fValue; }
int fValue;
int fMax;
};

class Buffer : public BLocker {
public:
#define limit(requested, max) (requested=(requested > max) ? max : requested)
friend class BufferGroup;
typedef enum {
EMPTY,
FILLING,
FILLED,
READING
} bufferState;
Buffer(size_t size, int index)
: BLocker("buffer"),
fIndex(index),
fUsed(0),
fSize(size),
fData((char*)malloc(size)),
fState(EMPTY)
{ }
~Buffer() { free(fData); }
// Caller handles locking!
inline size_t fillable() { return fSize - fUsed; }
inline char* fillPos() { return fData + fUsed; }
inline bool isFull() { return fUsed == fSize; }
inline bufferState state() { return fState; }
void setState(bufferState state) {
if (state == EMPTY) fUsed = 0;
fState = state;
}
inline char* data() { return fData; }
inline size_t readable() { return fUsed; }
size_t fill(char* data, size_t size) {
if (limit(size, fillable())) {
memcpy(fillPos(), data, size);
fUsed += size;
}
return size;
}
size_t read(char* data, size_t size) {
if (limit(size, readable())) {
memcpy(data, fData, size);
};
return size;
}
protected:
bufferState fState;
size_t fSize;
size_t fUsed;
char* fData;
int fIndex;
};
typedef Buffer* pBuffer;

class BufferGroup : public BLocker {
public:
#define none -1
typedef bool (*LimitFunc)(void* cookie, float ratio, bool isOk);
BufferGroup(int numBuffers, size_t size)
: BLocker("buffers"),
firstEmpty(numBuffers, 0),
firstFilled(numBuffers, none),
fNumBuffers(numBuffers)
{
buffers = new pBuffer[numBuffers];
for (int i = 0; i < numBuffers; i++)
buffers[i] = new Buffer(size, i);
}
~BufferGroup() {
for (int i = 0; i < fNumBuffers; i++) {
delete buffers[i];
}
delete buffers;
}
inline int IndexOf(Buffer* buffer) {
return buffer->fIndex;
}
Buffer* RequestForFilling(Buffer* previous = NULL) {
Buffer* result = NULL;
Lock();
if (previous) {
if (previous->CountLocks() == 0) previous->Lock();
previous->fState = Buffer::FILLED;
if (firstFilled == none) {
firstFilled = IndexOf(previous);
}
previous->Unlock();
}
if (firstEmpty != none) {
result = buffers[firstEmpty++];
result->fState = Buffer::FILLING;
if (buffers[firstEmpty]->fState != Buffer::EMPTY)
firstEmpty = none;
}
Unlock();
return result;
}
Buffer* RequestForReading(Buffer* previous = NULL) {
Buffer* result = NULL;
Lock();
if (previous) {
if (previous->CountLocks() == 0) previous->Lock();
previous->setState(Buffer::EMPTY);
if (firstEmpty == none)
firstEmpty = IndexOf(previous);
previous->Unlock();
}
if (firstFilled != none) {
result = buffers[firstFilled++];
result->fState = Buffer::READING;
if (buffers[firstFilled]->fState != Buffer::FILLED)
firstFilled = none;
}
Unlock();
return result;
}
void ReturnBuffer(Buffer* previous) {
if (previous->CountLocks() == 0) previous->Lock();
if (previous->fState == Buffer::FILLING && previous->fUsed == 0)
previous->setState(Buffer::EMPTY);

Lock();
switch (previous->fState) {
case Buffer::READING :
case Buffer::EMPTY:
previous->setState(Buffer::EMPTY);
if (firstEmpty == none) firstEmpty = IndexOf(previous);
break;
case Buffer::FILLING:
previous->fState = Buffer::FILLED;
case Buffer::FILLED:
if (firstFilled == none) firstFilled = previous->fIndex;
break;
}
Unlock();
previous->Unlock();
}
size_t TotalUsed() {
size_t result = 0;
for (int i=0; i<fNumBuffers; i++) {
Buffer* b=buffers[i];
if (b->fState == Buffer::FILLED || b->fState == Buffer::FILLING) {
result += b->fUsed;
}
}
return result;
}
size_t TotalCapacity() {
return fNumBuffers * buffers[0]->fSize;
}
float FillRatio() {
if (firstFilled == none)
return 0.0f;
else if (firstEmpty == none)
return 1.0f;
else
return float(firstEmpty - firstFilled) / fNumBuffers;
}
private:
int fNumBuffers;
pBuffer* buffers;
rotor firstEmpty;
rotor firstFilled;
};

#endif /* BUFFERING_H */

43 changes: 43 additions & 0 deletions Debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* File: Debug.h
* Author: Kai Niessen
*
* Created on January 16, 2016, 7:50 PM
*
* Contains definitions for tracing, debugging, profiling and logging
*
* To enable trace / debug / rpofiling messages, uncomment the associated
* defines or configure them in your IDE / make file.
*/

#ifndef DEBUG_H
#define DEBUG_H

#undef TRACE
#undef DEBUG
#undef MSG

//#define TRACING
//#define DEBUGGING
//#define PROFILING

#ifdef DEBUGGING
#define DEBUG(x...) fprintf(stderr, __FILE__ " - " x)
#else
#define DEBUG(x...)
#endif // DEBUGGING
#ifdef TRACING
#define TRACE(x...) fprintf(stderr, __FILE__ " - " x)
#else
#define TRACE(x...)
#endif // TRACING
#define MSG(x...) fprintf(stderr, __FILE__ " - " x)
#ifdef PROFILING
#define PROFILE_START bigtime_t timer = system_time()
#define PROFILE_MEASURE(action) TRACE("%s took %2.6f seconds\r\n", action, (system_time() - timer) / 1000000.0f)
#else
#define PROFILE_START
#define PROFILE_MEASURE(action)
#endif // PROFILING

#endif // DEBUG_H
Loading

0 comments on commit 54d3bb1

Please sign in to comment.