Exemplo n.º 1
0
void AudioPrefsDialog::load()
{
	bug_fun();
	cfg.load();
	cfg.dump();

	for(auto page: pages)
	{
		bug_var(page);

		for(auto iter = page->GetIterator(); !iter.AtEnd(); iter.Next())
		{
			auto prop = iter.GetProperty();
			auto key = prop->GetName().ToStdString();
			if(!cfg.has(key))
				continue;
			if(auto p = dynamic_cast<wxStringProperty*>(prop))
				p->SetValueFromString(cfg.get(key, p->GetDefaultValue().GetString().ToStdString()));
			else if(auto p = dynamic_cast<wxColourProperty*>(prop))
				{}
			else if(auto p = dynamic_cast<wxEnumProperty*>(prop))
			{
				p->SetValueFromString(cfg.get(key, p->GetDefaultValue().GetString().ToStdString()));
			}
			else if(auto p = dynamic_cast<wxIntProperty*>(prop))
				p->SetValueFromInt(cfg.get(key, p->GetDefaultValue().GetInteger()));
			else if(auto p = dynamic_cast<wxFontProperty*>(prop))
			{
				bug_var(p->GetValue().GetString().ToStdString());
				p->SetValueFromInt(cfg.get(key, p->GetDefaultValue().GetInteger()));
			}
		}
	}
}
Exemplo n.º 2
0
void SoundIoPlayer::stop()
{
	bug_fun();
	ctx_lock_guard lock(ctx_mtx);
	if(ctx)
		soundio_flush_events(ctx->sio);
	ctx.reset();
}
Exemplo n.º 3
0
void SoundIoPlayer::shutdown()
{
	bug_fun();
//	SoundIoPlayer::ctx_lock_guard lock(ctx_mtx);
//	ctx.reset();
	wxThreadEvent evt(wxEVT_THREAD, ID_PlayerEnded);
//	evt.SetExtraLong(player.pos);
	frame.GetEventHandler()->QueueEvent(evt.Clone());
}
Exemplo n.º 4
0
void SoundIoPlayer::unpause()
{
	bug_fun();
	if(auto err = soundio_outstream_pause(ctx->out, false))
		logit("E: pause: " << soundio_strerror(err));
	else
	{
		paused = false;
	}
}
Exemplo n.º 5
0
void SoundIoPlayer::pause()
{
	bug_fun();
	soundio_flush_events(ctx->sio);
	if(auto err = soundio_outstream_pause(ctx->out, true))
		logit("E: pause: " << soundio_strerror(err));
	else
	{
		paused = true;
	}
}
Exemplo n.º 6
0
void AudioPrefsDialog::save()
{
	bug_fun();

	cfg.start_transaction();

	for(auto page: pages)
	{
		bug_var(page);

		for(auto iter = page->GetIterator(); !iter.AtEnd(); iter.Next())
		{
			auto prop = iter.GetProperty();
			auto key = prop->GetName().ToStdString();
			bug_var(key);

			if(auto p = dynamic_cast<wxStringProperty*>(prop))
				cfg.set(key, p->GetValue().GetString().ToStdString());
			else if(auto p = dynamic_cast<wxColourProperty*>(prop))
				{}
			else if(auto p = dynamic_cast<wxEnumProperty*>(prop))
			{
				auto type = cfg.get("wx." + key + ".type", "str");
				if(type == "str")
					cfg.set(key, p->GetValueAsString().ToStdString());
				else if(type == "int")
					cfg.set(key, p->GetValue().GetInteger());
			}
			else if(auto p = dynamic_cast<wxIntProperty*>(prop))
			{
				cfg.set(key, p->GetValue().GetLong());
			}
		}
	}
	cfg.commit();
}
Exemplo n.º 7
0
bool FServerIrcBotPlugin::initialize()
{
	bug_fun();

	log("I: Starting queue processing");
	process_queues_fut = std::async(std::launch::async, [&]{process_queues();});

	add
	(
		  "files" // trigger
		, "@ammo" // default alias
		, "<no help found>" // default help
		, [&](const message& msg){ files(msg); }
	);
	add
	(
		  "serve"
		, "!ammo"
		, "<filename> - download specific file."
		, [&](const message& msg){ serve(msg); }
	);
	bot.add_monitor(*this);
	return true;
}
Exemplo n.º 8
0
void AudioPrefsDialog::OnPGChanged(wxPropertyGridEvent& event)
{
	bug_fun();
	bug_var(event.GetPropertyName().ToStdString());
	bug_var(event.GetProperty()->GetValue().GetString().ToStdString());
}
Exemplo n.º 9
0
void FServerIrcBotPlugin::exit()
{
	bug_fun();

	// stop queue processing
	log("I: Stopping queue procssing");
	done.store(true);

	// wait for send queue to complete (with timeout)
	log("I: Waiting for send queue to complete");
	if(process_queues_fut.valid())
	{
		auto status = process_queues_fut.wait_for(std::chrono::seconds(30));
		if(status == std::future_status::ready)
			process_queues_fut.get();
		else
		{
			log("E: time-out for queue processing thread to die");
		}
	}

	// notify wait queue of termination
	log("I: Notifying wait queue of termination");
	lock_guard lock(wait_q.get_mtx());

//	uint32 fid;
//	decltype(entries.begin()) found;
//
//	while(!wait_q.empty())
//	{
//		if(wait_q.pop_front(fid))
//		{
//			if((found = entries.find(fid)) != entries.end())
//			{
//				bot.fc_reply_pm_notice(found->second.msg, "DCC removed from queue: server shutting down.");
//				entries.erase(found);
//			}
//		}
//	}
//
//	// wait for transfers to complete
//	log("I: Waiting for transfers to complete");
//
//	st_clk::time_point timeout = st_clk::now() + std::chrono::minutes(5);
//	uint32 count = 1;
//	while(count && st_clk::now() < timeout)
//	{
//		count = 0;
//		uint64 size = 0;
//		uint64 sent = 0;
//		for(auto&& p: entries)
//		{
//			if(!p.second.size || p.second.size == p.second.sent)
//				continue;
//
//			size += p.second.size;
//			sent += p.second.sent;
//			++count;
//		}
//		log("I: Transfers: [" << count << "] " << (sent * 100 / size) << "% complete");
//		std::this_thread::sleep_for(std::chrono::seconds(3));
//	}
//
//	if(count)
//	{
//		log("E: times out waiting for transfers disconnecting them:");
//		for(auto&& p: entries)
//			if(p.second.size && p.second.size != p.second.sent)
//				bot.fc_reply_pm_notice(found->second.msg, "DCC aborting transfer: server shutting down.");
//	}
//
//	entries.clear();
}
Exemplo n.º 10
0
void FServerIrcBotPlugin::dcc_send_file_by_id(uint32 ip, uint32 port, uint32 fid, uint32 pos)
{
	bug_fun();
	bug_var(ip);
	bug_var(port);
	bug_var(fid);

	auto found = send_q.get_data().end();

	str userhost;

	{
		lock_guard lock(send_q.get_mtx());

		for(auto e = send_q.get_data().begin(); e != send_q.get_data().end(); ++e)
		{
			if(e->fid != fid)
				continue;

			found = e;
			break;
		}

		if(found == send_q.get_data().end())
		{
			log("E: file id not found: " << fid);
			return;
		}
	}

	userhost = found->userhost;

	str host = ntoa(ip);
	bug_var(host);
	bug_var(found->fid);
	bug_var(found->pathname);
	bug_var(found->userhost);

	found->fut = std::async(std::launch::async, [found, host, port, pos]
	{
//		netstream ns;
//
//		ns.open(host, std::to_string(port));
//
//		if(!ns)
//		{
//			log("E: opening connection to: " << host << ":" << port);
//			return;
//		}

		std::ifstream ifs;
		ifs.open(found->pathname, std::ios::binary|std::ios::ate);

		if(!ifs)
		{
			log("E: opening file to send: " << found->pathname);
			return;
		}

		found->size = ifs.tellg();
		ifs.seekg(pos);
		found->sent = ifs.tellg();

		bug_var((bool)ifs);

		hostent* he;
		if(!(he = gethostbyname(host.c_str())))
		{
			log("E: " << std::strerror(errno));
			return;
		}

		int sd;
		if((sd = socket(PF_INET, SOCK_STREAM, 0)) == -1)
		{
			log("E: " << std::strerror(errno));
			return;
		}

		auto sd_closer = make_logged_unistd_closer(sd);

		sockaddr_in sin;
		memcpy(&sin.sin_addr.s_addr, he->h_addr, he->h_length);

		sin.sin_family = AF_INET;
		sin.sin_port = htons(port);
		sin.sin_addr = *((in_addr*) he->h_addr);

		if(connect(sd, (sockaddr*) &sin, sizeof(sin)) < 0)
		{
			log("E: " << std::strerror(errno));
			return;
		}

		// working code
//		int len;
//		char buf[1024];
//		while(ifs.read(buf, sizeof(buf)), ifs.gcount())
//		{
//			bug_var(ifs.gcount());
//			if((len = send(sd, buf, ifs.gcount(), 0)) < 0)
//			{
//				log("E: writing to client failed: " << std::strerror(errno));
//				found->error = true;
//				return;
//			}
//
//			if(len < ifs.gcount())
//			{
//				log("E: sent less data than expected: " << len << " < " << ifs.gcount());
//				found->error = true;
//			}
//
//			found->sent += len;
//			bug_var(found->sent);
//		}

		int len;
		char buf[1024];
		while(ifs.read(buf, sizeof(buf)), ifs.gcount())
		{
			bug_var(ifs.gcount());
			auto to_send = ifs.gcount();
			while((len = send(sd, buf, to_send, 0)) != to_send)
			{
				if(len < 1)
				{
					log("E: writing to client failed: " << std::strerror(errno));
					found->error = true;
					return;
				}

				found->sent += len;
				bug_var(found->sent);

				if(!(to_send -= len))
					break;
			}
		}

		if(!ifs.eof())
		{
			log("E: reading incomplete: ");
			found->error = true;
		}

		found->sent = found->size;
	});

	log("I: File sent to " << userhost);
}
Exemplo n.º 11
0
void SoundIoPlayer::play(region reg, bool loop)
{
	bug_fun();
	bug_var(reg.b);
	bug_var(reg.e);
	bug_var(loop);

	if(is_playing())
		return;

//	AudioContextUPtr ctx(new AudioContext(soundio_create()));
	AudioContextUPtr ctx(new AudioContext());

	if(!ctx)
	{
		logit("E: SoundIo out of memory: ");
		return;
	}

	Config& cfg = app.config();

	auto backend = SoundIoBackend(
		cfg.get("soundio.backend", int(SoundIoBackendNone)));

	auto device_id = cfg.get("soundio.device", str());
	auto old_device_id = device_id;

	if(!ctx->initialize(backend, device_id))
		return;

	if(old_device_id != device_id)
		cfg.set("soundio.device", device_id);

//	if(auto err =
//	(backend == SoundIoBackendNone) ? soundio_connect(ctx->sio) :
//		soundio_connect_backend(ctx->sio, backend))
//	{
//		logit("E: SoundIo can't connect to backend: " << soundio_strerror(err));
//		return;
//	}
//
//	soundio_flush_events(ctx->sio);
//
//	auto selected_device_index = -1;
//
//	auto device_id = cfg.get("soundio.device", str());
//
//	selected_device_index = -1;
//
//	if(!device_id.empty())
//	{
//		auto device_count = soundio_output_device_count(ctx->sio);
//		for(decltype(device_count) i = 0; i < device_count; ++i)
//		{
//			SoundIoDevice* device = soundio_get_output_device(ctx->sio, i);
//			if(!std::strcmp(device->id, device_id.c_str()))
//			{
//				selected_device_index = i;
//				break;
//			}
//		}
//	}
//
//	if(selected_device_index == -1)
//		selected_device_index = soundio_default_output_device_index(ctx->sio);
//
//
//	if(selected_device_index == -1)
//	{
//		logit("E: SoundIo can't find device: ");
//		return;
//	}
//
//	if(!(ctx->dev = soundio_get_output_device(ctx->sio, selected_device_index)))
//	{
//		logit("E: SoundIo out of memory: ");
//		return;
//	}
//
//	if(std::strcmp(ctx->dev->id, device_id.c_str()))
//	{
//		device_id = ctx->dev->id;
//		// update current configured device
//		cfg.set("soundio.device", device_id);
//	}
//
//	if(ctx->dev->probe_error)
//	{
//		logit("E: Cannot probe device: " << soundio_strerror(ctx->dev->probe_error));
//		return;
//	}
//
//	if(!(ctx->out = soundio_outstream_create(ctx->dev)))
//	{
//		logit("E: SoundIo out of memory: ");
//		return;
//	}

	ctx->out->write_callback = write_callback;
	ctx->out->underflow_callback = underflow_callback;
	ctx->out->name = "Sound Killer (libsoundio)";
	ctx->out->userdata = this;
	ctx->out->sample_rate = audio.rate;
	ctx->out->software_latency = 0.1;

	if(soundio_device_supports_format(ctx->dev, SoundIoFormatFloat64NE))
	{
		ctx->out->format = SoundIoFormatFloat64NE;
		write_sample = write_sample_float64ne;
	}
	else if(soundio_device_supports_format(ctx->dev, SoundIoFormatFloat32NE))
	{
		ctx->out->format = SoundIoFormatFloat32NE;
		write_sample = write_sample_float32ne;
	}
	else if(soundio_device_supports_format(ctx->dev, SoundIoFormatS32NE))
	{
		ctx->out->format = SoundIoFormatS32NE;
		write_sample = write_sample_s32ne;
	}
	else if(soundio_device_supports_format(ctx->dev, SoundIoFormatS16NE))
	{
		ctx->out->format = SoundIoFormatS16NE;
		write_sample = write_sample_s16ne;
	}
	else
	{
		logit("E: No suitable device format available.");
		return;
	}

//	if(auto err = soundio_outstream_open(ctx->out))
//	{
//		logit("E: unable to open device: " << soundio_strerror(err));
//		return;
//	}
//
//	if(ctx->out->layout_error)
//	{
//		logit("E: unable to set channel layout: " << ctx->out->layout_error);
//		return;
//	}

	if(!ctx->open())
		return;

	{
		audiogang::write_lock lock(audio.mtx);
		this->reg = reg;
		this->loop = loop;
		this->pos = reg.b;
	}

//	if(auto err = soundio_outstream_start(ctx->out))
//	{
//		logit("E: unable to start device: " << soundio_strerror(err));
//		return;
//	}

	if(ctx->start())
	{
		ctx_lock_guard lock(ctx_mtx);
		this->ctx = std::move(ctx);
	}
}
Exemplo n.º 12
0
SoundIoPlayer::~SoundIoPlayer()
{
	bug_fun();
//	stop();
}