text:
package fi.uef.envi.emrooz.io.licor;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.commons.io.FilenameUtils;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.openrdf.model.URI;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.sail.nativerdf.NativeStore;

import fi.uef.envi.emrooz.Emrooz;
import fi.uef.envi.emrooz.cassandra.CassandraDataStore;
import fi.uef.envi.emrooz.entity.qb.ComponentProperty;
import fi.uef.envi.emrooz.entity.qb.ComponentPropertyValueDouble;
import fi.uef.envi.emrooz.entity.qb.ComponentPropertyValueInteger;
import fi.uef.envi.emrooz.entity.qb.ComponentPropertyValueLong;
import fi.uef.envi.emrooz.entity.qb.ComponentPropertyValueString;
import fi.uef.envi.emrooz.entity.qb.Dataset;
import fi.uef.envi.emrooz.entity.qb.DatasetObservation;
import fi.uef.envi.emrooz.entity.qudt.QuantityValue;
import fi.uef.envi.emrooz.entity.qudt.Unit;
import fi.uef.envi.emrooz.entity.time.Instant;
import fi.uef.envi.emrooz.sesame.SesameKnowledgeStore;
import fi.uef.envi.emrooz.vocabulary.QUDTUnit;

/**
 *

 * Title: GHGDatasetObservationReader
 *

 *

 * Description:
 *

 *

 * Project: Emrooz
 *

 *

 * Copyright: Copyright (C) 2015
 *

 *
 * @author Markus Stocker
 */

public class GHGDatasetObservationReader extends
		AbstractGHGObservationReader<DatasetObservation> {

	private DatasetObservation next;

	private Queue<DatasetObservation> observations;

	private URI gasDatasetId;
	private URI biometDatasetId;

	private static final Logger log = Logger
			.getLogger(GHGDatasetObservationReader.class.getName());

	public GHGDatasetObservationReader(File file, URI ns, URI gasDatasetId,
			URI biometDatasetId) {
		super(ns);

		if (file == null)
			throw new NullPointerException("[file = null]");
		if (gasDatasetId == null)
			throw new NullPointerException("[gasDatasetId = null]");
		if (biometDatasetId == null)
			throw new NullPointerException("[biometDatasetId = null]");

		this.gasDatasetId = gasDatasetId;
		this.biometDatasetId = biometDatasetId;
		this.observations = new LinkedList<DatasetObservation>();

		listFiles(file);
	}

	@Override
	public boolean hasNext() {
		if (!observations.isEmpty()) {
			next = observations.poll();
			return true;
		}

		if (!files.isEmpty()) {
			File file = files.poll();

			if (log.isLoggable(Level.INFO))
				log.info("Processing file [file = " + file + "]");

			String fileName = file.getName();
			String fileBaseName = FilenameUtils.getBaseName(fileName);
			String gasDataFileName = fileBaseName + ".data";
			String biometDataFileName = fileBaseName + "-biomet.data";

			processFile(file, fileName, gasDataFileName, gasDatasetId,
					gasProperties, gasPropertyTypes, GAS_ANALYZER_TIMEZONE_ROW,
					GAS_ANALYZER_TIMEZONE_COL, GAS_ANALYZER_DATA_ROW,
					GAS_ANALYZER_DATE_COL, GAS_ANALYZER_TIME_COL);

			processFile(file, fileName, biometDataFileName, biometDatasetId,
					biometProperties, biometPropertyTypes, BIOMET_TIMEZONE_ROW,
					BIOMET_TIMEZONE_COL, BIOMET_DATA_ROW, BIOMET_DATE_COL,
					BIOMET_TIME_COL);

			next = observations.poll();

			return true;
		}

		return false;
	}

	@Override
	public DatasetObservation next() {
		return next;
	}

	private void processFile(File file, String fileName, String dataFileName,
			URI datasetId, ComponentProperty[] properties, String[] types,
			int timeZoneRow, int timeZoneCol, int dataRow, int dateCol,
			int timeCol) {
		List<String> lines = readFile(file, fileName, dataFileName);
		DateTimeZone dateTimeZone = getDateTimeZone(lines.get(timeZoneRow),
				timeZoneCol);

		for (int i = dataRow; i < lines.size(); i++) {
			String line = lines.get(i);
			String[] cols = line.split(COLUMN_SEPARATOR);

			if (cols.length == 0) {
				if (log.isLoggable(Level.WARNING))
					log.warning("Empty data line [line = " + line + "; file = "
							+ file + "]");
				continue;
			}

			DateTime dateTime = getDateTime(cols[dateCol], cols[timeCol],
					dateTimeZone);

			observations.add(getDatasetObservation(datasetId, dateTime, cols,
					properties, types, dataFileName, i));
		}
	}

	private DatasetObservation getDatasetObservation(URI datasetId,
			DateTime dateTime, String[] cols, ComponentProperty[] properties,
			String[] types, String dataFileName, int nrow) {
		DatasetObservation ret = new DatasetObservation(_id(), datasetId,
				new Instant(_id(), dateTime));

		for (int i = 1; i < cols.length; i++) {
			String type = null;
			ComponentProperty property = null;
			String value = null;

			try {
				type = types[i];
				property = properties[i];
				value = cols[i];
			} catch (ArrayIndexOutOfBoundsException e) {
				log.severe("Index out of bounds [i = " + i + "; length = "
						+ cols.length + "]");
				continue;
			}

			value = value.replaceAll("\\s", "");

			if (type.equals("Double")) {
				try {
					ret.addComponent(
							property,
							new ComponentPropertyValueDouble(Double
									.valueOf(value)));
				} catch (NumberFormatException e) {
					ret.addComponent(property,
							new ComponentPropertyValueDouble(Double.NaN));
				}
			} else if (type.equals("String")) {
				ret.addComponent(property, new ComponentPropertyValueString(
						value));
			} else if (type.equals("Long")) {
				try {
					ret.addComponent(property, new ComponentPropertyValueLong(
							Long.valueOf(value)));
				} catch (NumberFormatException e) {
					ret.addComponent(property,
							new ComponentPropertyValueDouble(Double.NaN));
				}
			} else if (type.equals("Integer")) {
				try {
					ret.addComponent(
							property,
							new ComponentPropertyValueInteger(Integer
									.valueOf(value)));
				} catch (NumberFormatException e) {
					ret.addComponent(property,
							new ComponentPropertyValueDouble(Double.NaN));
				}
			} else {
				if (log.isLoggable(Level.SEVERE))
					log.severe("Unsupported component property value type [type = "
							+ type + "]");
			}
		}

		return ret;
	}

	public static void main(String[] args) {
		if (args.length == 0)
			help();

		File file = null;
		URI ns = null;
		URI gasDatasetId = null;
		URI biometDatasetId = null;
		File knowledgeStoreFile = null;
		String dataStoreHost = "localhost";

		for (int i = 0; i < args.length; i++) {
			if (args[i].equals("-f"))
				file = new File(args[++i]);
			if (args[i].equals("-ns"))
				ns = vf.createURI(args[++i]);
			if (args[i].equals("-gd"))
				gasDatasetId = vf.createURI(args[++i]);
			if (args[i].equals("-bd"))
				biometDatasetId = vf.createURI(args[++i]);
			if (args[i].equals("-ks"))
				knowledgeStoreFile = new File(args[++i]);
			if (args[i].equals("-ds"))
				dataStoreHost = args[++i];
		}

		if (file == null || ns == null || gasDatasetId == null
				|| biometDatasetId == null || knowledgeStoreFile == null)
			help();

		SesameKnowledgeStore ks = new SesameKnowledgeStore(new SailRepository(
				new NativeStore(knowledgeStoreFile)));
		ks.addDataset(new Dataset(gasDatasetId, new QuantityValue(_id(ns),
				GAS_ANALYZER_SAMPLING_FREQUENCY, new Unit(QUDTUnit.Hertz))));
		ks.addDataset(new Dataset(biometDatasetId, new QuantityValue(_id(ns),
				BIOMET_SAMPLING_FREQUENCY, new Unit(QUDTUnit.Hertz))));

		CassandraDataStore ds = new CassandraDataStore(dataStoreHost);

		Emrooz e = new Emrooz(ks, ds);

		long start = System.currentTimeMillis();

		status("Processing: " + file);

		GHGDatasetObservationReader reader = new GHGDatasetObservationReader(
				file, ns, gasDatasetId, biometDatasetId);

		long numOfObservations = 0;

		while (reader.hasNext()) {
			e.add(reader.next());
			numOfObservations++;
		}

		long end = System.currentTimeMillis();

		e.close();

		summary(start, end, numOfObservations, dataStoreHost);
	}

	private static void help() {
		StringBuffer sb = new StringBuffer();

		sb.append(GHGDatasetObservationReader.class.getName() + LINE_SEPARATOR);
		sb.append("Arguments:" + LINE_SEPARATOR);
		sb.append("  -f  [file name]       Name of the *.ghg file or a directory containing files"
				+ LINE_SEPARATOR);
		sb.append("  -ns [URI]             Name space for dataset observations (e.g. http://example.org)"
				+ LINE_SEPARATOR);
		sb.append("  -gd [URI]             The URI identifier for the gas dataset"
				+ LINE_SEPARATOR);
		sb.append("  -bd [URI]             The URI identifier for the biomet dataset"
				+ LINE_SEPARATOR);
		sb.append("  -ks [directory name]  Knowledge store data directory (e.g. /tmp/ks)"
				+ LINE_SEPARATOR);
		sb.append("  -ds [host name]       Data store host name (default: localhost)"
				+ LINE_SEPARATOR);

		System.out.println(sb);

		System.exit(0);
	}

}


text:
import CalendarDays from "../base/CalendarDays.js";
import { defaultState } from "../base/internal.js";
import PlainCalendarDay from "./PlainCalendarDay.js";

/**
 * CalendarDays component in the Plain reference design system
 *
 * @inherits CalendarDays
 * @part {PlainCalendarDay} day
 */
class PlainCalendarDays extends CalendarDays {
  // @ts-ignore
  get [defaultState]() {
    return Object.assign(super[defaultState], {
      dayPartType: PlainCalendarDay,
    });
  }
}

export default PlainCalendarDays;

redpajama_set_name: RedPajamaGithub


text:
@interface ImageCarouselViewController () <ImageCarouselCellDelegate>
@property(nonatomic, strong) NSArray* images;
@end

@implementation ImageCarouselViewController

-(instancetype) initWithImages:(NSArray *)images
{
    self = [super initWithCollectionViewLayout:[UIUtil defaultCollectionViewLayout]];
    if(self) {
        self.images = images;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.collectionView.backgroundColor = [UIColor clearColor];
    self.automaticallyAdjustsScrollViewInsets = NO;

    [self.collectionView registerNib:[UINib nibWithNibName:@"ImageCarouselCell" bundle:nil] forCellWithReuseIdentifier:@"ImageCarouselCell"];

    self.collectionView.pagingEnabled = YES;
    self.collectionView.dataSource = self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.collectionView reloadData];
}

-(BOOL)prefersStatusBarHidden
{
    return YES;
}

#pragma mark - UICollectionViewDataSource

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.images.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellType = @"ImageCarouselCell";
    ImageCarouselCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellType forIndexPath:indexPath];

    UIImage* image = [self.images objectAtIndex:indexPath.row];

    [cell setupWithImage:image number:(indexPath.row+1) outOf:self.images.count];
    cell.delegate = self;

    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return self.collectionView.bounds.size;
}

#pragma mark - ImageCarouselViewControllerDelegate

- (void) closeButtonPressed
{
    if(self.delegate) {
        [self.delegate controllerShouldDismiss:self];
    }
}

@end


text:
module Jumoku
  # Used only as a namespace. Useful for duck typing criteria: both
  # `Plexus::Edge` and `Plexus::Arc` are seen as `Branch`.
  #
  module Branch; end

  # Delegates to `Plexus::Edge`.
  #
  class UndirectedBranch < Plexus::Edge
    include Branch
  end

  # Delegates to `Plexus::Arc`.
  #
  class DirectedBranch   < Plexus::Arc
    include Branch
  end
end


text:
#include "../../Tuesday/Sources/Tuesday.h"

Tuesday_PatternGen Tuesday;
Tuesday_Settings TuesdaySettings;
Tuesday_Params TuesdayParams;
Tuesday_RandomGen MainRandom;
long oldseed = -1;

extern "C"
{
	extern int tickssincecommit;

	extern struct denoise_state_t algosw_state;
	extern struct denoise_state_t scalesw_state;
	extern struct denoise_state_t beatsw_state;
	extern struct denoise_state_t tpbsw_state;

	void __cdecl doTick()
	{
		Tuesday_Tick(&Tuesday, &TuesdayParams);
	}

	void __cdecl DoClock(int state)
	{
		Tuesday_Clock(&Tuesday, &TuesdaySettings, &TuesdayParams, state);
	}
}

// ImGui - standalone example application for SDL2 + OpenGL
// If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.)
// (GL3W is a helper library to access OpenGL functions since there is no standard header to access modern OpenGL functions easily. Alternatives are GLEW, Glad, etc.)

#include "imgui.h"
#include "../TestFrameImgUI/imgui_impl_sdl_gl3.h"
#include <stdio.h>
#include <GL/gl3w.h>    // This example is using gl3w to access OpenGL functions (because it is small). You may use glew/glad/glLoadGen/etc. whatever already works for you.
#include <SDL.h>

//#include "../../WobblerV2/Sources/Wobbler2.h"

#include "../libs/lodepng-master/lodepng.h"
extern "C"
{
	void SaveSettingsEeprom()
	{

	}

	void SaveCalibrationEeprom()
	{

	}
	void SaveEeprom()
	{
	}
}

SDL_Surface* load_PNG(const char* filename)
{
	std::vector<unsigned char> buffer, image;
	lodepng::load_file(buffer, filename); //load the image file with given filename
	unsigned w, h;
	unsigned error = lodepng::decode(image, w, h, buffer); //decode the png

	if (error)
	{
		//std::cout << "decoder error " << error << ": " << lodepng_error_text(error) << std::endl;
		return 0;
	}

	Uint32 rmask, gmask, bmask, amask;
	/* SDL interprets each pixel as a 32-bit number, so our masks must depend
	on the endianness (byte order) of the machine */
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
	rmask = 0xff000000;
	gmask = 0x00ff0000;
	bmask = 0x0000ff00;
	amask = 0x000000ff;
#else
	rmask = 0x000000ff;
	gmask = 0x0000ff00;
	bmask = 0x00ff0000;
	amask = 0xff000000;
#endif

	//avoid too large window size by downscaling large image
	unsigned jump = 1;
	//if(w / 1024 >= jump) jump = w / 1024 + 1;
	//if(h / 1024 >= jump) jump = h / 1024 + 1;

	SDL_Surface *dest = SDL_CreateRGBSurface(0, w, h, 32,
		rmask, gmask, bmask, amask);
	if (dest == NULL) {
		fprintf(stderr, "CreateRGBSurface failed: %s\n", SDL_GetError());
		return 0;
	}

	if (SDL_MUSTLOCK(dest)) { SDL_LockSurface(dest); }

	//plot the pixels of the PNG file
	for (unsigned y = 0; y + jump - 1 < h; y += jump)
		for (unsigned x = 0; x + jump - 1 < w; x += jump)
		{
			//get RGBA components
			Uint32 r = image[4 * y * w + 4 * x + 0]; //red
			Uint32 g = image[4 * y * w + 4 * x + 1]; //green
			Uint32 b = image[4 * y * w + 4 * x + 2]; //blue
			Uint32 a = image[4 * y * w + 4 * x + 3]; //alpha

													 //make translucency visible by placing checkerboard pattern behind image
													 //int checkerColor = 191 + 64 * (((x / 16) % 2) == ((y / 16) % 2));
													 //r = (a * r + (255 - a) * checkerColor) / 255;
													 //g = (a * g + (255 - a) * checkerColor) / 255;
													 //b = (a * b + (255 - a) * checkerColor) / 255;

													 //give the color value to the pixel of the screenbuffer
			Uint32* bufp = (Uint32 *)dest->pixels + (y * dest->pitch / 4) / jump + (x / jump);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
			* bufp = 0x01000000 * r + 65536 * g + 256 * b + a;
#else
			*bufp = 0x01000000 * a + 65536 * b + 256 * g + r;
#endif
		}

	if (SDL_MUSTLOCK(dest)) { SDL_UnlockSurface(dest); }
	return dest;
}

void SetupIcon(SDL_Window *window)
{

	SDL_SetWindowIcon(window, load_PNG("favicon-32x32.png"));

}

enum
{
	ADC_TEMPO,
	ADC_X,
	ADC_Y,
	ADC_BANG,
	ADC_COUNT
};
int cursor = 0;
ImVec2 Points[1000];
ImVec2 EnvPoints[1000];
ImVec2 Points2[1000];

typedef struct res_Struct
{
	bool clkin, beatled, tickled, clkout, loopled, acc, gate;
	int leds[16];
	int notecv;
	int velcv;

}
res_Struct;

res_Struct res[10000];

bool Knob(const char* label, float* value_p, float minv, float maxv)
{
	ImGuiStyle& style = ImGui::GetStyle();
	float line_height = ImGui::GetTextLineHeight();

	ImVec2 p = ImGui::GetCursorScreenPos();
	float sz = 76.0f;
	float radius = sz * 0.5f;
	ImVec2 center = ImVec2(p.x + radius, p.y + radius + line_height);
	float val1 = (value_p[0] - minv) / (maxv - minv);
	char textval[32];
	sprintf_s(textval, 32, "%04.1f", value_p[0]);

	ImVec2 textpos = p;

	float gamma = M_PI / 4.0f;//0 value in knob
	float alpha = (M_PI - gamma)*val1 * 2 + gamma;

	ImGui::InvisibleButton(label, ImVec2(sz, sz + line_height + style.ItemInnerSpacing.y));

	bool is_active = ImGui::IsItemActive();
	bool is_hovered = ImGui::IsItemHovered();
	bool touched = false;

	if (is_active)
	{
		touched = true;
		ImVec2 mp = ImGui::GetIO().MousePos;
		alpha = atan2f(mp.x - center.x, center.y - mp.y) + M_PI;
		alpha = __max(gamma, __min(2.0f*M_PI - gamma, alpha));
		float value = 0.5f*(alpha - gamma) / (M_PI - gamma);
		value_p[0] = value * (maxv - minv) + minv;
	}

	ImU32 col32 = is_active ? ImColor(255, 250, 100) : is_hovered ? ImColor(255, 250, 120) : ImColor(255, 250, 0);
	ImU32 col32line = ImColor(255, 255, 255);
	ImU32 col32text = ImGui::GetColorU32(ImGuiCol_Text);
	ImDrawList* draw_list = ImGui::GetWindowDrawList();

	radius *= 0.7;
	float x2 = -sinf(alpha)*radius*1.15 + center.x;
	float y2 = cosf(alpha)*radius*1.15 + center.y;

	draw_list->AddCircleFilled(center, radius, IM_COL32(0, 0, 0, 255), 32);
	draw_list->AddCircleFilled(center, radius*0.9, IM_COL32(10, 10, 10, 255), 32);
	draw_list->AddCircleFilled(center, radius*0.72, col32, 32);
	draw_list->AddLine(center, ImVec2(x2, y2), col32line, 4);
	//draw_list->AddText(textpos, col32text, textval);

	auto S = ImGui::CalcTextSize(label);
	draw_list->AddText(ImVec2(p.x + sz / 2 - S.x / 2, p.y), col32text, label);

	return touched;
}

int main(int, char**)
{
	Tuesday_Init(&Tuesday);

	Tuesday_LoadSettings(&TuesdaySettings, &TuesdayParams);
	Tuesday_RandomSeed(&MainRandom, oldseed);
	EuroRack_InitCalibration();

	Tuesday_SetupClockSubdivision(&Tuesday, &TuesdaySettings, &TuesdayParams);
	Tuesday_LoadDefaults(&TuesdaySettings, &TuesdayParams);

	Tuesday_Generate(&Tuesday, &TuesdayParams, &TuesdaySettings);
	// Setup SDL
	if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0)
	{
		printf("Error: %s\n", SDL_GetError());
		return -1;
	}

	// Setup window
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
	SDL_DisplayMode current;
	SDL_GetCurrentDisplayMode(0, &current);
	SDL_Window *window = SDL_CreateWindow("TiNRS Tuesday Inspection GUI", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1580, 720, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
	SetupIcon(window);
	SDL_GLContext glcontext = SDL_GL_CreateContext(window);
	SDL_GL_SetSwapInterval(1); // Enable vsync
	gl3wInit();

	// Setup ImGui binding
	ImGui::CreateContext();
	ImGuiIO& io = ImGui::GetIO(); (void)io;
	//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;  // Enable Keyboard Controls
	ImGui_ImplSdlGL3_Init(window);

	// Setup style
	ImGui::StyleColorsLight();

	ImVec4 clear_color = ImVec4(1.0f / 255.0f, 58.0f / 255.0f, 66.0f / 255.0f, 1.00f);

	// racing turqoise: 1,58,66
	// haringmuts geel: 255, 234,0

#define RACINGGREEN IM_COL32(1, 58, 66, 255)

	bool done = false;
	static int counter = 0;
	static int updaterate = 1;
	static int spacerate = 1;
	static int T = 0;
	static bool externalclock = true;
	static int clocktiming = 10;
	bool manualclock = true;

	bool clockval = false;
	bool resetval = false;

	float fX = 0, fY = 0, fBang = 1, fTempo = 0;
	int32_t clkcolor = ImColor::HSV(0, 1, 1);
	int32_t tickcolor = ImColor::HSV(0.25, 1, 1);;// IM_COL32(0, 128, 255, 255);
	int32_t beatcolor = ImColor::HSV(0.5, 1, 1);
	int32_t loopcolor = ImColor::HSV(0.75, 1, 1);

	int32_t clklinecolor = ImColor::HSV(0, 1, 1, 0.5);
	int32_t ticklinecolor = ImColor::HSV(0.25, 1, 1, 0.5);;// IM_COL32(0, 128, 255, 255);
	int32_t beatlinecolor = ImColor::HSV(0.5, 1, 1, 0.5);
	int32_t looplinecolor = ImColor::HSV(0.75, 1, 1, 0.5);

	int32_t gatecolor = ImColor::HSV(0, 0, 0.3);
	int32_t accentcolor = ImColor::HSV(0, 0, 1);

	ImFont* pFont = io.Fonts->AddFontFromFileTTF("Fontfabric - Panton.otf", 14.0f);
	ImFont* pFontBold = io.Fonts->AddFontFromFileTTF("Fontfabric - Panton ExtraBold.otf", 18.0f);

	unsigned char * pixels;
	int width, height, bytes_per_pixels;

	ImGui::GetStyle().ItemInnerSpacing = ImVec2(5, 5);;
	ImGui::GetStyle().ItemSpacing = ImVec2(5, 5);
	ImGui::GetStyle().FramePadding = ImVec2(5, 5);
	ImGui::GetStyle().Colors[ImGuiCol_WindowBg] = ImVec4(1.0f, 1.0f, 1.0f, .800f);
	static bool parameters = true;
	static bool waveoutputs = true;
	static bool simsettings = true;
	static bool reset = false;
	static bool patternview = true;
	bool processtimerticksautomatically;
	bool knobs = true;

	bool inclk = false;
	static bool lastclk = true;

	Tuesday.UIMode = UI_NORMAL;
	while (!done)
	{
		SDL_Event event;
		while (SDL_PollEvent(&event))
		{
			ImGui_ImplSdlGL3_ProcessEvent(&event);
			if (event.type == SDL_QUIT)
				done = true;
		}
		ImGui_ImplSdlGL3_NewFrame(window);

		if (ImGui::BeginMainMenuBar())
		{

			if (ImGui::BeginMenu("Tuesday Windows"))
			{
				ImGui::MenuItem("Output Waveforms", NULL, &waveoutputs);
				ImGui::MenuItem("Tuesday Parameters", NULL, &parameters);
				ImGui::MenuItem("Sim settings", NULL, &simsettings);
				ImGui::MenuItem("Patternview", NULL, &patternview);
				ImGui::MenuItem("Knobs?", NULL, &knobs);
				ImGui::EndMenu();
			}
			ImGui::EndMainMenuBar();
		}
		if (patternview)
		{
			ImGui::PushFont(pFontBold);

				ImGui::Begin("Pattern", &patternview, ImGuiWindowFlags_AlwaysAutoResize);
				ImGui::PushFont(pFont);

					ImGui::BeginChild("PTN", ImVec2(1000, 540), true);
					ImVec2 P = ImGui::GetCursorScreenPos();
					float xs = 930 / (float)(Tuesday.CurrentPattern.Length);
					float ys = 4;
					float  H = 540;
					int minnote = 10000;
					int maxnote = -10000;
						for (int i = 0; i < Tuesday.CurrentPattern.Length; i++)
						{
							int n = Tuesday.CurrentPattern.Ticks[i].note;

							if (n < minnote) minnote = n;
							if (n > maxnote) maxnote = n;
						}
						ys = H / (36 );

						for (int i = 0; i <= 36; i++)
						{
							int n = i;
							int b[12] = { 0,1,0,1,0,0,1,0,1,0,1,0 };
							ImGui::GetWindowDrawList()->AddRectFilled(ImVec2( P.x, P.y + H - (ys*0.9 + i * ys)), ImVec2(1000 + P.x, P.y + H - (i * ys)), b[n%12]?0x50000000:0x40f0f0f0, 2.0);
						}

					for (int i = 0; i < Tuesday.CurrentPattern.Length; i++)
					{
						int n = Tuesday.CurrentPattern.Ticks[i].note;
						float L = (Tuesday.CurrentPattern.Ticks[i].maxsubticklength) / 6.0;
						ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(70+P.x + i * xs, P.y + H-(ys+n*ys)), ImVec2(70+P.x + (i + L) * xs,P.y +H-( n*ys)),0xff50f0f0, 2.0);
						ImGui::GetWindowDrawList()->AddRect(ImVec2(70 + P.x + i * xs, P.y + H - (ys + n * ys)), ImVec2(70 + P.x + (i + L) * xs, P.y + H - (n * ys)), 0xdf808080, 2.0);
						ImGui::GetWindowDrawList()->AddRectFilled(ImVec2(20+ P.x, P.y + H - (ys + n * ys)), ImVec2(20 +ys + P.x , P.y + H - (n * ys)), 0xff50f0f0, 4.0);
					}
					ImGui::EndChild();

				ImGui::PopFont();
				ImGui::End();
				ImGui::PopFont();

		}
		if (simsettings)
		{
			ImGui::PushFont(pFontBold);
			{
				ImGui::Begin("Simulator", &simsettings, ImGuiWindowFlags_AlwaysAutoResize);
				ImGui::PushFont(pFont);

				ImGui::Checkbox("external clock", &externalclock);
				if (externalclock)
				{
					ImGui::Checkbox("process timerticks always", &processtimerticksautomatically);
					ImGui::Checkbox("manual clock", &manualclock);
					if (manualclock)
					{
						ImGui::Checkbox("clock", &clockval);

					}
					else
					{
						ImGui::SliderInt("clockspacing", &clocktiming, 1, 20);
					}

					static int subdiv = 0;
					static int lastsubdiv = -1;
					ImGui::Text("subdiv mode:"); ImGui::SameLine();
					ImGui::RadioButton("1:1", &subdiv, 0); ImGui::SameLine();
					ImGui::RadioButton("1:2", &subdiv, 1); ImGui::SameLine();
					ImGui::RadioButton("16ppqn", &subdiv, 2); ImGui::SameLine();
					ImGui::RadioButton("24ppqn", &subdiv, 3);
					if (subdiv != lastsubdiv)
					{
						TuesdaySettings.ClockSubDivMode = subdiv;
						lastsubdiv = subdiv;
						Tuesday_SetupClockSubdivision(&Tuesday, &TuesdaySettings, &TuesdayParams);
					}
				}

				if (ImGui::Checkbox("ResetIn", &reset))
				{
					Tuesday_Reset(&Tuesday, &TuesdaySettings, reset ? 1 : 0);
				}

				bool ClockDownSlope = (TuesdaySettings.ClockMode & CLOCKMODE_DOWNSLOPE) > 0;
				bool ClockResetModeInverted = (TuesdaySettings.ClockMode & CLOCKMODE_RESETINVERTED) > 0;
				bool ClockResetHaltsPulses = (TuesdaySettings.ClockMode & CLOCKMODE_RESET_BLOCKS_TICKS) > 0;
				if (ImGui::Button("ClockModeCycle"))
				{
					TuesdaySettings.ClockMode = (TuesdaySettings.ClockMode + 1) % 8;
				}

				ImGui::Text(ClockDownSlope ? "Slope: Down" : "Slope: Up"); ImGui::SameLine(); if (ImGui::Button("toggle slope")) { Tuesday_ToggleSlope(&TuesdaySettings); };
				ImGui::Text(ClockResetModeInverted ? "Reset: Inverted (runmode)" : "Reset: Normal"); ImGui::SameLine(); if (ImGui::Button("toggle reset")) { Tuesday_ToggleReset(&TuesdaySettings); };
				ImGui::Text(ClockResetHaltsPulses ? "ResetBlock: Blocking" : "ResetBlock: Reset pattern only"); ImGui::SameLine(); if (ImGui::Button("toggle resetblock")) { Tuesday_ToggleResetPattern(&TuesdaySettings); };
				ImGui::Text("AlgoID: %d", (int)TuesdaySettings.algooptions[TuesdayParams.algo] & 0xf);
				ImGui::Text("ScaleID: %d", (int)TuesdaySettings.scale[TuesdayParams.scale]);
				ImGui::Text("TPBopt: %d", (int)TuesdaySettings.tpboptions[TuesdayParams.tpbopt]);
				ImGui::Text("BeatOpt: %d", (int)TuesdaySettings.beatoptions[TuesdayParams.beatopt]);

				static bool algo_lengthmode = false;
				static bool algo_slides = false;
				static bool algo_lengthmulti = false;

				ImGui::Checkbox("Slides", &algo_slides);
				ImGui::Checkbox("LengthMode", &algo_lengthmode);
				ImGui::Checkbox("LengthMult", &algo_lengthmulti);

				static int algot = 3;
				ImGui::Text("CurrentAlgo:"); ImGui::SameLine();

				ImGui::RadioButton("TESTS", &algot, 0); ImGui::SameLine();
				ImGui::RadioButton("TRITRANCE", &algot, 1); ImGui::SameLine();
				ImGui::RadioButton("STOMPER", &algot, 2); ImGui::SameLine();
				ImGui::RadioButton("MARKOV", &algot, 3); //ImGui::SameLine();
				ImGui::RadioButton("WOBBLER", &algot, 4); ImGui::SameLine();
				ImGui::RadioButton("CHIPARP1", &algot, 5); ImGui::SameLine();
				ImGui::RadioButton("CHIPARP2", &algot, 6); ImGui::SameLine();
				ImGui::RadioButton("SNH", &algot, 7); //ImGui::SameLine();
				ImGui::RadioButton("SAIKOCLASSIC", &algot, 8); ImGui::SameLine();
				ImGui::RadioButton("NEOSAIKO", &algot, 9); ImGui::SameLine();
				ImGui::RadioButton("SCALEWALKER", &algot, 10); ImGui::SameLine();
				ImGui::RadioButton("TOOEASY", &algot, 11);// ImGui::SameLine();
				ImGui::RadioButton("RANDOM", &algot, 12); ImGui::SameLine();
				ImGui::RadioButton("alg14", &algot, 13); ImGui::SameLine();
				ImGui::RadioButton("alg15", &algot, 14); ImGui::SameLine();
				ImGui::RadioButton("alg16", &algot, 15); //ImGui::SameLine();

				TuesdaySettings.algooptions[TuesdayParams.algo] = algot;

				ImGui::Text("algo%d", (int)TuesdaySettings.algooptions[TuesdayParams.algo] & 0xf);

				static int scalet = 3;
				ImGui::Text("CurrentScale:"); ImGui::SameLine();

				ImGui::RadioButton("MAJOR", &scalet, 0); ImGui::SameLine();
				ImGui::RadioButton("MINOR", &scalet, 1); ImGui::SameLine();
				ImGui::RadioButton("DORIAN", &scalet, 2); ImGui::SameLine();
				ImGui::RadioButton("BLUES", &scalet, 3); //ImGui::SameLine();
				ImGui::RadioButton("PENTA", &scalet, 4); ImGui::SameLine();
				ImGui::RadioButton("12TONE", &scalet, 5); ImGui::SameLine();
				ImGui::RadioButton("MAJORTRIAD", &scalet, 6); ImGui::SameLine();
				ImGui::RadioButton("MINORTRIAD", &scalet, 7); //ImGui::SameLine();
				if (ImGui::Button("regen"))
				{
					Tuesday.switchmode = 1;
				}
		/*	SCALE_EGYPTIAN,
					SCALE_PHRYGIAN,
					SCALE_LOCRIAN,
					SCALE_OCTATONIC,
					SCALE_MELODICMINOR,
					SCALE_MINORPENTA,
					SCALE_15,
					SCALE_16,
					*/

				TuesdaySettings.scale[TuesdayParams.scale] = scalet;

				ImGui::Text("scale: %d", (int)TuesdaySettings.scale[TuesdayParams.scale] & 0xf);

				//TuesdaySettings.algooptions[algo] = (TuesdaySettings.algooptions[algo] & 0xf) + (algo_lengthmode ? (1 << 5) : 0) + (algo_slides ? (1 << 4) : 0) + (algo_lengthmulti ? (1 << 6) : 0);

			/*	static int lastopts = -1;
				if (algo + beats + scale + ticks != lastopts)
				{
					lastopts = algo + beats + scale + ticks;
					Tuesday.switchmode = 1;
				}*/
				ImGui::SliderInt("Update Speed", &updaterate, 0, 20);
				ImGui::SliderInt("Space Speed", &spacerate, 1, 20);

				ImGui::PopFont();
				ImGui::End();
				ImGui::PopFont();
			}
		}
		if (parameters)
		{
			ImGui::PushFont(pFontBold);
			{
				ImGui::Begin("Tuesday", &parameters, ImGuiWindowFlags_AlwaysAutoResize);
				ImGui::PushFont(pFont);
				{
					if (knobs)
					{
						for (int i = 0; i < 16; i++) { tickssincecommit++; Tuesday_SetupLeds(&Tuesday, &TuesdaySettings, &TuesdayParams); }

						Knob("Tempo", &fTempo, 0.0f, 1.0f); ImGui::SameLine();
						Knob("X", &fX, 0.0f, 1.0f); ImGui::SameLine();
						Knob("Y", &fY, 0.0f, 1.0f); ImGui::SameLine();
						Knob("!", &fBang, 0.0f, 1.0f);

						if (ImGui::Button("Tick"))
						{
							tpbsw_state.pressed = 1;
						}
						ImGui::SameLine();
						if (ImGui::Button("Tick(long)"))
						{
							tpbsw_state.pressed = 1;
							tpbsw_state.longpressed = 2000;
						}
						ImGui::SameLine(); ImGui::ColorButton("b1", ImVec4(1, Tuesday.RStateLeds[0] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("b2", ImVec4(1, Tuesday.RStateLeds[1] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("b3", ImVec4(1, Tuesday.RStateLeds[2] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("b4", ImVec4(1, Tuesday.RStateLeds[3] / 255.0f, 0, 1));

						if (ImGui::Button("Beat"))
						{
							beatsw_state.pressed = 1;
						}
						ImGui::SameLine();
						if (ImGui::Button("Beat(long)"))
						{
							beatsw_state.pressed = 1;
							beatsw_state.longpressed = 2000;
						}

						ImGui::SameLine(); ImGui::ColorButton("t1", ImVec4(1, Tuesday.RStateLeds[4] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("t2", ImVec4(1, Tuesday.RStateLeds[5] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("t3", ImVec4(1, Tuesday.RStateLeds[6] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("t4", ImVec4(1, Tuesday.RStateLeds[7] / 255.0f, 0, 1));

						if (ImGui::Button("Scale"))
						{
							scalesw_state.pressed = 1;

						}
						ImGui::SameLine();
						if (ImGui::Button("Scale(long)"))
						{
							scalesw_state.pressed = 1;
							scalesw_state.longpressed = 2000;
						}

						ImGui::SameLine(); ImGui::ColorButton("a1", ImVec4(1, Tuesday.RStateLeds[8] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("a2", ImVec4(1, Tuesday.RStateLeds[9] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("a3", ImVec4(1, Tuesday.RStateLeds[10] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("a4", ImVec4(1, Tuesday.RStateLeds[11] / 255.0f, 0, 1));

						if (ImGui::Button("Algo"))
						{
							algosw_state.pressed = 1;
						}
						ImGui::SameLine();
						if (ImGui::Button("Algo(long)"))
						{
							algosw_state.pressed = 1;
							algosw_state.longpressed = 2000;
						}

						ImGui::SameLine(); ImGui::ColorButton("s1", ImVec4(1, Tuesday.RStateLeds[12] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("s2", ImVec4(1, Tuesday.RStateLeds[13] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("s3", ImVec4(1, Tuesday.RStateLeds[14] / 255.0f, 0, 1));
						ImGui::SameLine(); ImGui::ColorButton("s4", ImVec4(1, Tuesday.RStateLeds[15] / 255.0f, 0, 1));

					}
					else
					{
						ImGui::SliderFloat("Tempo", &fTempo, 0.0f, 1.0f);
						ImGui::SliderFloat("X", &fX, 0.0f, 1.0f);
						ImGui::SliderFloat("Y", &fY, 0.0f, 1.0f);
						ImGui::SliderFloat("!", &fBang, 0.0f, 1.0f);
					}

				}

				ImGui::PopFont();
				ImGui::End();
				ImGui::PopFont();
			}
		}

		int minN = 100000;
		int maxN = -100000;
		int minP = 100000;
		int maxP = -100000;

		uint16_t adcchannels[ADC_COUNT];
		adcchannels[ADC_X] = (int)((1 - fX) * 0xffff);
		adcchannels[ADC_Y] = (int)((1 - fY) * 0xffff);
		adcchannels[ADC_TEMPO] = (int)((1 - fTempo) * 0xffff);
		adcchannels[ADC_BANG] = (int)((1 - fBang) * 0xffff);;

		Tuesday.seed1 = (adcchannels[ADC_X] >> 8);
		Tuesday.seed2 = (adcchannels[ADC_Y] >> 8);
		Tuesday.intensity = (adcchannels[ADC_BANG] >> 8);
		Tuesday.tempo = (adcchannels[ADC_TEMPO] >> 8);
		long newseed = (Tuesday.seed1) + (Tuesday.seed2 << 8);
		if (newseed != oldseed) Tuesday.switchmode = 1;

		if (Tuesday.switchmode == 1)
		{
			Tuesday.switchmode = 0;
			Tuesday_RandomSeed(&MainRandom, newseed);
			Tuesday_Generate(&Tuesday, &TuesdayParams, &TuesdaySettings);
			oldseed = newseed;
		}

		Tuesday_MainLoop(&Tuesday, &TuesdaySettings, &TuesdayParams);

		for (int i = 0; i < updaterate*10 ; i++)
		{
			T++;
			inclk = false;
			bool dotimertick = true;

			if (externalclock)
			{
				dotimertick = processtimerticksautomatically;
				if (manualclock)
				{
					if (clockval) inclk = true;

				}
				else
				{
					if (T % (clocktiming * 15) < ((clocktiming * 15) / 2))
					{
						inclk = true;
					}

				}
			}
			res[cursor].clkin = inclk;
			if (lastclk != inclk)
			{
				dotimertick = true;
				Tuesday_ExtClock(&Tuesday, &TuesdayParams, &TuesdaySettings, inclk ? 1 : 0);
				lastclk = inclk;
			}
			if (dotimertick)
			{
				Tuesday_TimerTick(&Tuesday, &TuesdayParams);
				for (int i = 0; i < spacerate*10 ; i++)
				{
					res[cursor].notecv = Tuesday.CVOut;
					res[cursor].gate = Tuesday.Gates[GATE_GATE] != 0;
					res[cursor].beatled = Tuesday.Gates[GATE_BEAT] != 0;
					res[cursor].tickled = Tuesday.Gates[GATE_TICK] != 0;
					res[cursor].clkout = Tuesday.Gates[GATE_CLOCK] != 0;
					res[cursor].acc = Tuesday.Gates[GATE_ACCENT] != 0;
					res[cursor].loopled = Tuesday.Gates[GATE_LOOP] != 0;

					cursor = (cursor + 1) % 10000;
				}
			}
		}

		ImVec2 p;

		if (waveoutputs) {
			ImGui::PushFont(pFontBold);
			ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(0, 0, 0, 255));
			ImGui::Begin("Wave outputs", &waveoutputs, ImGuiWindowFlags_AlwaysAutoResize);
			ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(255, 255, 200, 255));
			ImGui::BeginChild("Normal", ImVec2(1000, 240), true);
			p = ImGui::GetCursorScreenPos();

			for (int i = 0; i < 500; i++)
			{
				int idx = (cursor - 1 - i*10  + 10000) % 10000;
				int idxb = (cursor - 1 - (i - 1)*10 + 10000) % 10000;
				int N = res[idx].notecv / 65536;
				if (N > maxN) maxN = N;
				if (N < minN) minN = N;

				Points[i].x = i * 2 + p.x;
				Points[i].y = p.y + 100 - ((N - 2048) / 20);
				bool gate = false;
				bool acc = false;
				bool beat = false;
				bool tick = false;
				bool loop = false;
				bool clk = false;
				for (int j = 0; j < 10; j++) {
					int residx = (idx - j + 10000) % 10000;
					if (res[residx ].gate) gate = true;
					if (res[residx ].tickled) tick = true;
					if (res[residx ].acc) acc = true;
					if (res[residx ].loopled) loop = true;
					if (res[residx ].beatled) beat = true;
					if (res[residx ].clkin) clk = true;
				};

				if (gate)
				{
					ImVec2 S(i * 2 + p.x, p.y + 100);
					ImGui::GetWindowDrawList()->AddCircleFilled(S, 2, gatecolor, 4);
				}
				if (acc)
				{
					ImVec2 S(i * 2 + p.x, p.y + 110);
					ImGui::GetWindowDrawList()->AddCircle(S, 3, accentcolor, 4);
				}

				if (clk)
				{
					ImVec2 S(i * 2 + p.x, p.y + 0);
					ImGui::GetWindowDrawList()->AddCircleFilled(S, 2, clkcolor, 4);
					ImGui::GetWindowDrawList()->AddLine(S, ImVec2(S.x, p.y + 100), clklinecolor);

				}

				if (loop)
				{
					ImVec2 S(i * 2 + p.x, p.y + 20);
					ImGui::GetWindowDrawList()->AddCircleFilled(S, 12, loopcolor, 12);
					ImGui::GetWindowDrawList()->AddLine(S, ImVec2(S.x, p.y + 100), looplinecolor, 5);

				}
				if (beat)
				{
					ImVec2 S(i * 2 + p.x, p.y + 40);
					ImGui::GetWindowDrawList()->AddCircleFilled(S, 8, beatcolor, 8);
					ImGui::GetWindowDrawList()->AddLine(S, ImVec2(S.x, p.y + 100), beatlinecolor, 3);

				}

				if (tick)
				{
					ImVec2 S(i * 2 + p.x, p.y + 60);
					ImGui::GetWindowDrawList()->AddCircleFilled(S, 4, tickcolor, 8);
					ImGui::GetWindowDrawList()->AddLine(S, ImVec2(S.x, p.y + 100), ticklinecolor);

				}

			}
			ImGui::GetWindowDrawList()->AddPolyline(Points, 500, IM_COL32(255, 255, 0, 255), false, 2.0f);

			ImGui::EndChild();
			ImGui::PushStyleColor(ImGuiCol_Text, loopcolor);
			ImGui::Text("LOOP"); ImGui::SameLine();
			ImGui::PopStyleColor();
			ImGui::PushStyleColor(ImGuiCol_Text, beatcolor);
			ImGui::Text("BEAT"); ImGui::SameLine();
			ImGui::PopStyleColor();
			ImGui::PushStyleColor(ImGuiCol_Text, tickcolor);
			ImGui::Text("TICK"); ImGui::SameLine();
			ImGui::PopStyleColor();
			ImGui::PushStyleColor(ImGuiCol_Text, clkcolor);
			ImGui::Text("CLOCK");
			ImGui::PopStyleColor();
			int32_t textcolo = ImColor::HSV(0, 0, 0.9);
			ImGui::PushStyleColor(ImGuiCol_Text, textcolo);
			char str[4][10] = { "1:1","1:2", "16ppqn", "24ppqn" };
			ImGui::Text("master clock mode: \"%s\"", str[TuesdaySettings.ClockSubDivMode]);
			ImGui::Text("%d ticks-per-beat", (int)TuesdaySettings.tpboptions[TuesdayParams.tpbopt]);
			ImGui::Text("%d beats-per-loop", (int)TuesdaySettings.beatoptions[TuesdayParams.beatopt]);
			ImGui::PopStyleColor();

			ImGui::PopStyleColor();
			ImGui::End();
			ImGui::PopStyleColor();
			ImGui::PopFont();
		}

		glViewport(0, 0, (int)ImGui::GetIO().DisplaySize.x, (int)ImGui::GetIO().DisplaySize.y);
		glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
		glClear(GL_COLOR_BUFFER_BIT);
		ImGui::Render();
		ImGui_ImplSdlGL3_RenderDrawData(ImGui::GetDrawData());
		//ImGui::PopFont();
		SDL_GL_SwapWindow(window);
		Sleep(1);
	}

	ImGui_ImplSdlGL3_Shutdown();
	ImGui::DestroyContext();

	SDL_GL_DeleteContext(glcontext);
	SDL_DestroyWindow(window);
	SDL_Quit();

	return 0;
}