Back again.
About making a in game store.
It's posible but not easy right now there is no score system.
The store fontend could be made in lua and there
It seems that Afterfx and the combo counter time is ignoring pausetime.
Another 2 bugs.
About fluidsytnh...
I have investigated and there are bindings for GO but are undocumented and I have not a single clue on how to use it.
I will try to build a basic command line app that loads a midi to get a hang on it.
EDIT
Also new features by neatunsou.
MatchRestart
[state test]
type = MatchRestart
trigger1 = time = 10
p1def = "kfm.def"
p2def = "kfm.def"
Stagedef = "stage0.def"
reload = 1,1
Reset the round and resume. (Same effect as debug key F4)
Set Reload to 1 to reload the file and restart the round from the beginning. (Same effect as the debug key Shift + F4)
One item of Reload specifies whether P1 or 2 item reloads P2. If all 0, do not reload and reset the round.
When the path of def file is specified in P1def, P2def, Stagedef, the file is read when reloading. The pass at that time is based on the execution character.
A interesting one it could be made for a boss that changes stages (And character def) in the second round for example.
IDK if this is somepart of the basic usage of Fluidsynth but let me share you, the little things do I have:
Standalone mode of fluidsynth
You can simply use fluidsynth to play MIDI files:
$ fluidsynth -a alsa -m alsa_seq -l -i /usr/share/soundfonts/FluidR3_GM.sf2 example.midi
assuming than you installed soundfont-fluid.
There are many other options to fluidsynth; see manpage or use -h to get help.
One may wish to use pulseaudio instead of alsa as the argument to the -a option.
Tip: The soundfont does not needed to be specified every time if a symbolic link created for the default soundfont, e.g.
ln -s FluidR3_GM.sf2 /usr/share/soundfonts/default.sf2
ALSA daemon mode
If you want fluidsynth to run as ALSA daemon, edit /etc/conf.d/fluidsynth and add your soundfont along with any other changes you would like to make. For e.g., fluidr3:
SOUND_FONT=/usr/share/soundfonts/FluidR3_GM.sf2
OTHER_OPTS='-a alsa -m alsa_seq -r 48000'
After that, you can start/enable the fluidsynth service. Note that you can't use root to restart the fluidsynth service, if you're using the pulseaudio driver. Pulseaudio won't allow root to connect, since the pulseaudio server is usually started by the user (and not root). You can solve it by creating a systemd/User service (replacing multi-user.target with default.target in the copied fluidsynth.service).
The following will give you an output software MIDI port (in addition of hardware MIDI ports on your system, if any):
$ aconnect -o
client 128: 'FLUID Synth (5117)' [type=user]
0 'Synth input port (5117:0)
An example of usage for this is aplaymidi:
$ aplaymidi -p128:0 example.midi
SDL_Mixer
To use fluidsynth with programs that use SDL_Mixer, you need to specify the soundfont as:
$ SDL_SOUNDFONTS=/usr/share/soundfonts/FluidR3_GM.sf2 ./program
Source link
https://wiki.archlinux.org/index.php/FluidSynth
http://www.fluidsynth.org/
http://www.fluidsynth.org/api/
Now, let me share you some info about the API (the bad thing is the library is a C library)
Creating and changing the settings
Before you can use the synthesizer, you have to create a settings object. The settings objects is used by many components of the FluidSynth library. It gives a unified API to set the parameters of the audio drivers, the midi drivers, the synthesizer, and so forth. A number of default settings are defined by the current implementation.
All settings have a name that follows the "dotted-name" notation. For example, "synth.polyphony" refers to the number of voices (polyphony) allocated by the synthesizer. The settings also have a type. There are currently three types: strings, numbers (double floats), and integers. You can change the values of a setting using the fluid_settings_setstr(), fluid_settings_setnum(), and fluid_settings_setint() functions. For example:
#include <fluidsynth.h>
int main(int argc, char** argv)
{
fluid_settings_t* settings = new_fluid_settings();
fluid_settings_setint(settings, "synth.polyphony", 128);
/* ... */
delete_fluid_settings(settings);
return 0;
}
The API contains the functions to query the type, the current value, the default value, the range and the "hints" of a setting. The range is the minimum and maximum value of the setting. The hints gives additional information about a setting. For example, whether a string represents a filename. Or whether a number should be interpreted on on a logarithmic scale. Check the settings.h API documentation for a description of all functions.
Creating the synthesizer
To create the synthesizer, you pass it the settings object, as in the following example:
#include <fluidsynth.h>
int main(int argc, char** argv)
{
fluid_settings_t* settings;
fluid_synth_t* synth;
settings = new_fluid_settings();
synth = new_fluid_synth(settings);
/* Do useful things here */
delete_fluid_synth(synth);
delete_fluid_settings(settings);
return 0;
For a full list of available synthesizer settings, please refer to FluidSettings Documentation.
Creating the Audio Driver
The synthesizer itself does not write any audio to the audio output. This allows application developers to manage the audio output themselves if they wish. The next section describes the use of the synthesizer without an audio driver in more detail.
Creating the audio driver is straightforward: set the audio.driver settings and create the driver object. Because the FluidSynth has support for several audio systems, you may want to change which one you want to use. The list below shows the audio systems that are currently supported. It displays the name, as used by the fluidsynth library, and a description.
jack: JACK Audio Connection Kit (Linux, Mac OS X, Windows)
alsa: Advanced Linux Sound Architecture (Linux)
oss: Open Sound System (Linux, Unix)
pulseaudio: PulseAudio (Linux, Mac OS X, Windows)
coreaudio: Apple CoreAudio (Mac OS X)
dsound: Microsoft DirectSound (Windows)
portaudio: PortAudio Library (Mac OS 9 & X, Windows, Linux)
sndman: Apple SoundManager (Mac OS Classic)
dart: DART sound driver (OS/2)
opensles: OpenSL ES (Android)
oboe: Oboe (Android)
file: Driver to output audio to a file
sdl2*: Simple DirectMedia Layer (Linux, Windows, Mac OS X, iOS, Android, FreeBSD, Haiku, etc.)
The default audio driver depends on the settings with which FluidSynth was compiled. You can get the default driver with fluid_settings_getstr_default(). To get the list of available drivers use the fluid_settings_foreach_option() function. Finally, you can set the driver with fluid_settings_setstr(). In most cases, the default driver should work out of the box.
Additional options that define the audio quality and latency are "audio.sample-format", "audio.period-size", and "audio.periods". The details are described later.
You create the audio driver with the new_fluid_audio_driver() function. This function takes the settings and synthesizer object as arguments. For example:
void init()
{
fluid_settings_t* settings;
fluid_synth_t* synth;
fluid_audio_driver_t* adriver;
settings = new_fluid_settings();
/* Set the synthesizer settings, if necessary */
synth = new_fluid_synth(settings);
fluid_settings_setstr(settings, "audio.driver", "jack");
adriver = new_fluid_audio_driver(settings, synth);
}
As soon as the audio driver is created, it will start playing. The audio driver creates a separate thread that uses the synthesizer object to generate the audio.
There are a number of general audio driver settings. The audio.driver settings define the audio subsystem that will be used. The audio.periods and audio.period-size settings define the latency and robustness against scheduling delays. There are additional settings for the audio subsystems used. For a full list of available audio driver settings, please refer to FluidSettings Documentation.
*Note: In order to use sdl2 as audio driver, the application is responsible for initializing SDL (e.g. with SDL_Init()). This must be done before the first call to new_fluid_settings()! Also make sure to call SDL_Quit() after all fluidsynth instances have been destroyed.
Using the synthesizer without an audio driver
It is possible to use the synthesizer object without creating an audio driver. This is desirable if the application using FluidSynth manages the audio output itself. The synthesizer has several API functions that can be used to obtain the audio output:
fluid_synth_write_s16() fills two buffers (left and right channel) with samples coded as signed 16 bits (the endian-ness is machine dependent). fluid_synth_write_float() fills a left and right audio buffer with 32 bits floating point samples. The function fluid_synth_process() is the generic interface for synthesizing audio, which is also capable of multi channel audio output.
Loading and managing SoundFonts
Before any sound can be produced, the synthesizer needs a SoundFont.
SoundFonts are loaded with the fluid_synth_sfload() function. The function takes the path to a SoundFont file and a boolean to indicate whether the presets of the MIDI channels should be updated after the SoundFont is loaded. When the boolean value is TRUE, all MIDI channel bank and program numbers will be refreshed, which may cause new instruments to be selected from the newly loaded SoundFont.
The synthesizer can load any number of SoundFonts. The loaded SoundFonts are treated as a stack, where each new loaded SoundFont is placed at the top of the stack. When selecting presets by bank and program numbers, SoundFonts are searched beginning at the top of the stack. In the case where there are presets in different SoundFonts with identical bank and program numbers, the preset from the most recently loaded SoundFont is used. The fluid_synth_program_select() can be used for unambiguously selecting a preset or bank offsets could be applied to each SoundFont with fluid_synth_set_bank_offset(), to try and ensure that each preset has unique bank and program numbers.
The fluid_synth_sfload() function returns the unique identifier of the loaded SoundFont, or -1 in case of an error. This identifier is used in subsequent management functions: fluid_synth_sfunload() removes the SoundFont, fluid_synth_sfreload() reloads the SoundFont. When a SoundFont is reloaded, it retains it's ID and position on the SoundFont stack.
Additional API functions are provided to get the number of loaded SoundFonts and to get a pointer to the SoundFont.
Creating a Real-time MIDI Driver
FluidSynth can process real-time MIDI events received from hardware MIDI ports or other applications. To do so, the client must create a MIDI input driver. It is a very similar process to the creation of the audio driver: you initialize some properties in a settings instance and call the new_fluid_midi_driver() function providing a callback function that will be invoked when a MIDI event is received. The following MIDI drivers are currently supported:
jack: JACK Audio Connection Kit MIDI driver (Linux, Mac OS X)
oss: Open Sound System raw MIDI (Linux, Unix)
alsa_raw: ALSA raw MIDI interface (Linux)
alsa_seq: ALSA sequencer MIDI interface (Linux)
winmidi: Microsoft Windows MM System (Windows)
midishare: MIDI Share (Linux, Mac OS X)
coremidi: Apple CoreMIDI (Mac OS X)
#include <fluidsynth.h>
int handle_midi_event(void* data, fluid_midi_event_t* event)
{
printf("event type: %d\n", fluid_midi_event_get_type(event));
}
int main(int argc, char** argv)
{
fluid_settings_t* settings;
fluid_midi_driver_t* mdriver;
settings = new_fluid_settings();
mdriver = new_fluid_midi_driver(settings, handle_midi_event, NULL);
/* ... */
delete_fluid_midi_driver(mdriver);
return 0;
}
There are a number of general MIDI driver settings. The midi.driver setting defines the MIDI subsystem that will be used. There are additional settings for the MIDI subsystems used. For a full list of available midi driver settings, please refer to FluidSettings Documentation.
Loading and Playing a MIDI file
FluidSynth can be used to play MIDI files, using the MIDI File Player interface. It follows a high level implementation, though its implementation is currently incomplete. After initializing the synthesizer, create the player passing the synth instance to new_fluid_player(). Then, you can add some SMF file names to the player using fluid_player_add(), and finally call fluid_player_play() to start the playback. You can check if the player has finished by calling fluid_player_get_status(), or wait for the player to terminate using fluid_player_join().
#include <fluidsynth.h>
int main(int argc, char** argv)
{
int i;
fluid_settings_t* settings;
fluid_synth_t* synth;
fluid_player_t* player;
fluid_audio_driver_t* adriver;
settings = new_fluid_settings();
synth = new_fluid_synth(settings);
player = new_fluid_player(synth);
adriver = new_fluid_audio_driver(settings, synth);
/* process command line arguments */
for (i = 1; i < argc; i++) {
if (fluid_is_soundfont(argv[i])) {
fluid_synth_sfload(synth, argv[1], 1);
}
if (fluid_is_midifile(argv[i])) {
fluid_player_add(player, argv[i]);
}
}
/* play the midi files, if any */
fluid_player_play(player);
/* wait for playback termination */
fluid_player_join(player);
/* cleanup */
delete_fluid_audio_driver(adriver);
delete_fluid_player(player);
delete_fluid_synth(synth);
delete_fluid_settings(settings);
return 0;
}
A list of available MIDI player settings can be found in FluidSettings Documentation.
Fast file renderer for non-realtime MIDI file rendering
Instead of creating an audio driver as described in section Loading and Playing a MIDI file one may chose to use the file renderer, which is the fastest way to synthesize MIDI files.
fluid_settings_t* settings;
fluid_synth_t* synth;
fluid_player_t* player;
fluid_file_renderer_t* renderer;
settings = new_fluid_settings();
// specify the file to store the audio to
// make sure you compiled fluidsynth with libsndfile to get a real wave file
// otherwise this file will only contain raw s16 stereo PCM
fluid_settings_setstr(settings, "audio.file.name", "/path/to/output.wav");
// use number of samples processed as timing source, rather than the system timer
fluid_settings_setstr(settings, "player.timing-source", "sample");
// since this is a non-realtime szenario, there is no need to pin the sample data
fluid_settings_setint(settings, "synth.lock-memory", 0);
synth = new_fluid_synth(settings);
// *** loading of a soundfont omitted ***
player = new_fluid_player(synth);
fluid_player_add(player, "/path/to/midifile.mid");
fluid_player_play(player);
renderer = new_fluid_file_renderer (synth);
while (fluid_player_get_status(player) == FLUID_PLAYER_PLAYING)
{
if (fluid_file_renderer_process_block(renderer) != FLUID_OK)
{
break;
}
}
// just for sure: stop the playback explicitly and wait until finished
fluid_player_stop(player);
fluid_player_join(player);
delete_fluid_file_renderer(renderer);
delete_fluid_player(player);
delete_fluid_synth(synth);
delete_fluid_settings(settings);
Various output files types are supported, if compiled with libsndfile. Those can be specified via the settings object as well. Refer to the FluidSettings Documentation for more audio.file.* options.
So, taking on mind the function of the Fluidsytnh API, now its time to understand the go bindings
So, From squeeky Fluidsyhnth binding, we will take on: Driver.go
package fluidsynth
// #cgo pkg-config: fluidsynth
// #include <fluidsynth.h>
// #include <stdlib.h>
import "C"
type AudioDriver struct {
ptr *C.fluid_audio_driver_t
}
func NewAudioDriver(settings Settings, synth Synth) AudioDriver {
return AudioDriver{C.new_fluid_audio_driver(settings.ptr, synth.ptr)}
}
func (d *AudioDriver) Delete() {
C.delete_fluid_audio_driver(d.ptr)
}
type FileRenderer struct {
ptr *C.fluid_file_renderer_t
}
func NewFileRenderer(synth Synth) FileRenderer {
return FileRenderer{C.new_fluid_file_renderer(synth.ptr)}
}
func (r *FileRenderer) Delete() {
C.delete_fluid_file_renderer(r.ptr)
}
func (r *FileRenderer) ProcessBlock() bool {
return C.fluid_file_renderer_process_block(r.ptr) == C.FLUID_OK
Now, we instrospect a little on: sound.go
import "C"
import (
"os"
"fmt"
"unsafe"
)
type Synth struct {
csettings *C.fluid_settings_t
csynth *C.fluid_synth_t
cdriver *C.fluid_audio_driver_t
ptr *C.fluid_synth_t
}
func NewSynth(settings map[string]interface{}) *Synth {
csettings, _ := C.new_fluid_settings()
for key, value := range settings {
ckey := C.CString(key)
switch value := value.(type) {
case string:
cval := C.CString(value)
C.fluid_settings_setstr(csettings, ckey, cval)
C.free(unsafe.Pointer(cval))
case int:
C.fluid_settings_setint(csettings, ckey, C.int(value))
case float64:
C.fluid_settings_setnum(csettings, ckey, C.double(value))
default:
fmt.Fprintf(os.Stderr, "NewSynth: ignoring setting %s: unhandled type %T\n", key, value)
}
C.free(unsafe.Pointer(ckey))
func cbool(b bool) C.int {
if b {
return 1
}
csynth := C.new_fluid_synth(csettings)
//cdriver := C.new_fluid_audio_driver(csettings, csynth)
return &Synth{csettings, csynth, nil}
return 0
}
func NewSynth(settings Settings) Synth {
return Synth{C.new_fluid_synth(settings.ptr)}
}
func (s *Synth) Delete() {
C.delete_fluid_synth(s.ptr)
}
func (s *Synth) SFLoad(path string, resetPresets bool) int {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
creset := C.int(1)
if !resetPresets {
creset = 0
}
cfont_id, _ := C.fluid_synth_sfload(s.csynth, cpath, creset)
creset := cbool(resetPresets)
cfont_id, _ := C.fluid_synth_sfload(s.ptr, cpath, creset)
return int(cfont_id)
}
/* XXX can this be run automatically on gc? */
func (s *Synth) Delete() {
//C.delete_fluid_audio_driver(s.cdriver)
C.delete_fluid_synth(s.csynth)
C.delete_fluid_settings(s.csettings)
}
func (s *Synth) NoteOn(channel, note, velocity uint8) {
C.fluid_synth_noteon(s.csynth, C.int(channel), C.int(note), C.int(velocity))
C.fluid_synth_noteon(s.ptr, C.int(channel), C.int(note), C.int(velocity))
}
func (s *Synth) NoteOff(channel, note uint8) {
C.fluid_synth_noteoff(s.csynth, C.int(channel), C.int(note))
C.fluid_synth_noteoff(s.ptr, C.int(channel), C.int(note))
}
func (s *Synth) ProgramChange(channel, program uint8) {
C.fluid_synth_program_change(s.csynth, C.int(channel), C.int(program))
C.fluid_synth_program_change(s.ptr, C.int(channel), C.int(program))
}
func (s *Synth) WriteFrames_int16(dst []int16) {
if len(dst) % 2 != 0 {
panic("dst not disivible by 2")
/* WriteS16 synthesizes signed 16-bit samples. It will fill as much of the provided
slices as it can without overflowing 'left' or 'right'. For interleaved stereo, have both
'left' and 'right' share a backing array and use lstride = rstride = 2. ie:
synth.WriteS16(samples, samples[1:], 2, 2)
*/
func (s *Synth) WriteS16(left, right []int16, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
cbuf := unsafe.Pointer(&dst[0])
C.fluid_synth_write_s16(s.csynth, C.int(len(dst)/2), cbuf, 0, 2, cbuf, 1, 2)
C.fluid_synth_write_s16(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}
func (s *Synth) WriteFloat(left, right []float32, lstride, rstride int) {
nframes := (len(left) + lstride - 1) / lstride
rframes := (len(right) + rstride - 1) / rstride
if rframes < nframes {
nframes = rframes
}
C.fluid_synth_write_float(s.ptr, C.int(nframes), unsafe.Pointer(&left[0]), 0, C.int(lstride), unsafe.Pointer(&right[0]), 0, C.int(rstride))
}
type TuningId struct {
Bank, Program uint8
}
/* ActivateKeyTuning creates/modifies a specific tuning bank/program */
func (s *Synth) ActivateKeyTuning(id TuningId, name string, tuning [128]float64, apply bool) {
n := C.CString(name)
defer C.free(unsafe.Pointer(n))
C.fluid_synth_activate_key_tuning(s.ptr, C.int(id.Bank), C.int(id.Program), n, (*C.double)(&tuning[0]), cbool(apply))
}
/* ActivateTuning switches a midi channel onto the specified tuning bank/program */
func (s *Synth) ActivateTuning(channel uint8, id TuningId, apply bool) {
C.fluid_synth_activate_tuning(s.ptr, C.int(channel), C.int(id.Bank), C.int(id.Program), cbool(apply))
And no less important, settings.go
package fluidsynth
// #cgo pkg-config: fluidsynth
// #include <fluidsynth.h>
// #include <stdlib.h>
import "C"
import (
"unsafe"
)
var settingNames map[string]*C.char
var nSettings = 0
type Settings struct {
ptr *C.fluid_settings_t
}
func NewSettings() Settings {
if settingNames == nil {
settingNames = make(map[string]*C.char)
}
nSettings++
return Settings{ptr: C.new_fluid_settings()}
}
func (s *Settings) Delete() {
nSettings--
if nSettings == 0 {
settingNames = nil
}
C.delete_fluid_settings(s.ptr)
}
func cname(name string) *C.char {
if cname, ok := settingNames[name]; ok {
return cname
}
cname := C.CString(name)
settingNames[name] = cname
return cname
}
/* IsRealtime returns true if changing the specified setting immediately affects an associated Synth */
func (s *Settings) IsRealtime(name string) bool {
return C.fluid_settings_is_realtime(s.ptr, cname(name)) == 1
}
func (s *Settings) SetInt(name string, val int) bool {
return C.fluid_settings_setint(s.ptr, cname(name), C.int(val)) == 1
}
func (s *Settings) SetNum(name string, val float64) bool {
return C.fluid_settings_setnum(s.ptr, cname(name), C.double(val)) == 1
}
func (s *Settings) SetString(name, val string) bool {
cval := C.CString(val)
defer C.free(unsafe.Pointer(cval))
return C.fluid_settings_setstr(s.ptr, cname(name), cval) == 1
}
func (s *Settings) GetInt(name string, val *int) bool {
return C.fluid_settings_getint(s.ptr, cname(name), (*C.int)(unsafe.Pointer(val))) == 1
}
func (s *Settings) GetNum(name string, val *float64) bool {
return C.fluid_settings_getnum(s.ptr, cname(name), (*C.double)(unsafe.Pointer(val))) == 1
}
func (s *Settings) GetString(name string, val *string) bool {
var cstr *C.char
ok := (C.fluid_settings_getstr(s.ptr, cname(name), &cstr) == 1)
if ok {
*val = C.GoString(cstr)
}
return ok
}
So, Having this on mind, lets analize main.go and sound.go
So, We begin on Main.go
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/yuin/gopher-lua"
)
func init() {
runtime.LockOSThread()
}
func chk(err error) {
if err != nil {
panic(err)
}
}
func createLog(p string) *os.File {
//fmt.Println("Creating log")
f, err := os.Create(p)
if err != nil {
panic(err)
}
return f
}
func closeLog(f *os.File) {
//fmt.Println("Closing log")
f.Close()
}
func main() {
if len(os.Args[1:]) > 0 {
sys.cmdFlags = make(map[string]string)
key := ""
player := 1
for _, a := range os.Args[1:] {
match, _ := regexp.MatchString("^-", a)
if match {
help, _ := regexp.MatchString("^-[h%?]", a)
if help {
fmt.Println("I.K.E.M.E.N\nOptions (case sensitive):")
fmt.Println(" -h -? Help")
fmt.Println(" -log <logfile> Records match data to <logfile>")
fmt.Println(" -r <sysfile> Loads motif <sysfile>. eg. -r motifdir or -r motifdir/system.def")
fmt.Println("\nQuick VS Options:")
fmt.Println(" -p<n> <playername> Loads player n, eg. -p3 kfm")
fmt.Println(" -p<n>.ai <level> Set player n's AI to <level>, eg. -p1.ai 8")
fmt.Println(" -p<n>.color <col> Set player n's color to <col>")
fmt.Println(" -p<n>.life <life> Sets player n's life to <life>")
fmt.Println(" -p<n>.power <power> Sets player n's power to <power>")
fmt.Println(" -rounds <num> Plays for <num> rounds, and then quits")
fmt.Println(" -s <stagename> Loads stage <stagename>")
fmt.Println("\nPress ENTER to exit.")
var s string
fmt.Scanln(&s)
os.Exit(0)
}
sys.cmdFlags[a] = ""
key = a
} else if key == "" {
sys.cmdFlags[fmt.Sprintf("-p%v", player)] = a
player += 1
} else {
sys.cmdFlags[key] = a
key = ""
}
}
}
chk(glfw.Init())
defer glfw.Terminate()
defcfg := []byte(strings.Join(strings.Split(`{
"HelperMax":56,
"PlayerProjectileMax":256,
"ExplodMax":512,
"AfterImageMax":128,
"MasterVolume":80,
"WavVolume":80,
"BgmVolume":80,
"Attack.LifeToPowerMul":0.7,
"GetHit.LifeToPowerMul":0.6,
"Width":640,
"Height":480,
"Super.TargetDefenceMul":1.5,
"LifebarFontScale":1,
"System":"script/main.lua",
"KeyConfig":[{
"Joystick":-1,
"Buttons":["UP","DOWN","LEFT","RIGHT","z","x","c","a","s","d","RETURN","q","w"]
},{
"Joystick":-1,
"Buttons":["t","g","f","h","j","k","l","u","i","o","RSHIFT","LEFTBRACKET","RIGHTBRACKET"]
}],
"JoystickConfig":[{
"Joystick":0,
"Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
},{
"Joystick":1,
"Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
}],
"Motif":"data/system.def",
"CommonAir":"data/common.air",
"CommonCmd":"data/common.cmd",
"SimulMode":true,
"LifeMul":100,
"Team1VS2Life":120,
"TurnsRecoveryRate":300,
"ZoomActive":false,
"ZoomMin":0.75,
"ZoomMax":1.1,
"ZoomSpeed":1,
"RoundTime":99,
"NumTurns":4,
"NumSimul":4,
"NumTag":4,
"Difficulty":8,
"Credits":10,
"ListenPort":7500,
"ContSelection":true,
"AIRandomColor":true,
"AIRamping":true,
"AutoGuard":false,
"TeamPowerShare":false,
"TeamLifeShare":false,
"Fullscreen":false,
"AudioDucking":false,
"QuickLaunch":0,
"AllowDebugKeys":true,
"PostProcessingShader": 0,
"LocalcoordScalingType": 1,
"IP":{
}
}
`, "\n"), "\r\n"))
tmp := struct {
HelperMax int32
PlayerProjectileMax int
ExplodMax int
AfterImageMax int32
MasterVolume int
WavVolume int
BgmVolume int
Attack_LifeToPowerMul float32 `json:"Attack.LifeToPowerMul"`
GetHit_LifeToPowerMul float32 `json:"GetHit.LifeToPowerMul"`
Width int32
Height int32
Super_TargetDefenceMul float32 `json:"Super.TargetDefenceMul"`
LifebarFontScale float32
System string
KeyConfig []struct {
Joystick int
Buttons []interface{}
}
JoystickConfig []struct {
Joystick int
Buttons []interface{}
}
NumTag int
TeamLifeShare bool
AIRandomColor bool
Fullscreen bool
AudioDucking bool
AllowDebugKeys bool
PostProcessingShader int32
LocalcoordScalingType int32
CommonAir string
CommonCmd string
QuickLaunch int
}{}
chk(json.Unmarshal(defcfg, &tmp))
const configFile = "data/config.json"
if bytes, err := ioutil.ReadFile(configFile); err != nil {
f, err := os.Create(configFile)
chk(err)
f.Write(defcfg)
chk(f.Close())
} else {
if len(bytes) >= 3 &&
bytes[0] == 0xef && bytes[1] == 0xbb && bytes[2] == 0xbf {
bytes = bytes[3:]
}
chk(json.Unmarshal(bytes, &tmp))
}
sys.helperMax = tmp.HelperMax
sys.playerProjectileMax = tmp.PlayerProjectileMax
sys.explodMax = tmp.ExplodMax
sys.afterImageMax = tmp.AfterImageMax
sys.attack_LifeToPowerMul = tmp.Attack_LifeToPowerMul
sys.getHit_LifeToPowerMul = tmp.GetHit_LifeToPowerMul
sys.super_TargetDefenceMul = tmp.Super_TargetDefenceMul
sys.lifebarFontScale = tmp.LifebarFontScale
sys.quickLaunch = tmp.QuickLaunch
sys.masterVolume = tmp.MasterVolume
sys.wavVolume = tmp.WavVolume
sys.bgmVolume = tmp.BgmVolume
sys.AudioDucking = tmp.AudioDucking
stoki := func(key string) int {
return int(StringToKey(key))
}
Atoi := func(key string) int {
var i int
i, _ = strconv.Atoi(key)
return i
}
for a := 0; a < tmp.NumTag; a++ {
for _, kc := range tmp.KeyConfig {
b := kc.Buttons
if kc.Joystick < 0 {
sys.keyConfig = append(sys.keyConfig, KeyConfig{kc.Joystick,
stoki(b[0].(string)), stoki(b[1].(string)),
stoki(b[2].(string)), stoki(b[3].(string)),
stoki(b[4].(string)), stoki(b[5].(string)), stoki(b[6].(string)),
stoki(b[7].(string)), stoki(b[8].(string)), stoki(b[9].(string)),
stoki(b[10].(string)), stoki(b[11].(string)), stoki(b[12].(string))})
}
}
for _, jc := range tmp.JoystickConfig {
b := jc.Buttons
if jc.Joystick >= 0 {
sys.JoystickConfig = append(sys.JoystickConfig, KeyConfig{jc.Joystick,
Atoi(b[0].(string)), Atoi(b[1].(string)),
Atoi(b[2].(string)), Atoi(b[3].(string)),
Atoi(b[4].(string)), Atoi(b[5].(string)), Atoi(b[6].(string)),
Atoi(b[7].(string)), Atoi(b[8].(string)), Atoi(b[9].(string)),
Atoi(b[10].(string)), Atoi(b[11].(string)), Atoi(b[12].(string))})
}
}
}
sys.teamLifeShare = tmp.TeamLifeShare
sys.fullscreen = tmp.Fullscreen
sys.PostProcessingShader = tmp.PostProcessingShader
sys.LocalcoordScalingType = tmp.LocalcoordScalingType
sys.aiRandomColor = tmp.AIRandomColor
sys.allowDebugKeys = tmp.AllowDebugKeys
air, err := ioutil.ReadFile(tmp.CommonAir)
if err != nil {
fmt.Print(err)
}
sys.commonAir = string("\n") + string(air)
cmd, err := ioutil.ReadFile(tmp.CommonCmd)
if err != nil {
fmt.Print(err)
}
sys.commonCmd = string("\n") + string(cmd)
//os.Mkdir("debug", os.ModeSticky|0755)
log := createLog("Ikemen.txt")
defer closeLog(log)
l := sys.init(tmp.Width, tmp.Height)
if err := l.DoFile(tmp.System); err != nil {
fmt.Fprintln(log, err)
switch err.(type) {
case *lua.ApiError:
errstr := strings.Split(err.Error(), "\n")[0]
if len(errstr) < 10 || errstr[len(errstr)-10:] != "<game end>" {
panic(err)
}
default:
panic(err)
}
}
if !sys.gameEnd {
sys.gameEnd = true
}
<-sys.audioClose
Now, lets make some commits
package main
import (
"C"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"runtime"
"strconv"
"strings"
"path/filepath"
"github.com/go-gl/glfw/v3.2/glfw"
"github.com/yuin/gopher-lua"
"github.com/x42/avldrums.lv2/tree/master/fluidsynth"
)
func init() {
runtime.LockOSThread()
}
func chk(err error) {
if err != nil {
panic(err)
}
}
func createLog(p string) *os.File {
//fmt.Println("Creating log")
f, err := os.Create(p)
if err != nil {
panic(err)
}
return f
}
func closeLog(f *os.File) {
//fmt.Println("Closing log")
f.Close()
}
func (s *Synth) SFLoad(path string, resetPresets bool) int {
cpath := C.CString(path)
defer C.free(unsafe.Pointer(cpath))
creset := C.int(1)
if !resetPresets {
creset = 0
}
cfont_id, _ := C.fluid_synth_sfload("data/gamesoundfont.sf2")
creset := cbool(resetPresets)
cfont_id, _ := C.fluid_synth_sfload("data/gamesoundfont.sf2")
return int(cfont_id)
}
func main() {
if len(os.Args[1:]) > 0 {
sys.cmdFlags = make(map[string]string)
key := ""
player := 1
for _, a := range os.Args[1:] {
match, _ := regexp.MatchString("^-", a)
if match {
help, _ := regexp.MatchString("^-[h%?]", a)
if help {
fmt.Println("I.K.E.M.E.N\nOptions (case sensitive):")
fmt.Println(" -h -? Help")
fmt.Println(" -log <logfile> Records match data to <logfile>")
fmt.Println(" -r <sysfile> Loads motif <sysfile>. eg. -r motifdir or -r motifdir/system.def")
fmt.Println("\nQuick VS Options:")
fmt.Println(" -p<n> <playername> Loads player n, eg. -p3 kfm")
fmt.Println(" -p<n>.ai <level> Set player n's AI to <level>, eg. -p1.ai 8")
fmt.Println(" -p<n>.color <col> Set player n's color to <col>")
fmt.Println(" -p<n>.life <life> Sets player n's life to <life>")
fmt.Println(" -p<n>.power <power> Sets player n's power to <power>")
fmt.Println(" -rounds <num> Plays for <num> rounds, and then quits")
fmt.Println(" -s <stagename> Loads stage <stagename>")
fmt.Println("\nPress ENTER to exit.")
var s string
fmt.Scanln(&s)
os.Exit(0)
}
sys.cmdFlags[a] = ""
key = a
} else if key == "" {
sys.cmdFlags[fmt.Sprintf("-p%v", player)] = a
player += 1
} else {
sys.cmdFlags[key] = a
key = ""
}
}
}
chk(glfw.Init())
defer glfw.Terminate()
defcfg := []byte(strings.Join(strings.Split(`{
"HelperMax":56,
"PlayerProjectileMax":256,
"ExplodMax":512,
"AfterImageMax":128,
"MasterVolume":80,
"WavVolume":80,
"BgmVolume":80,
"Attack.LifeToPowerMul":0.7,
"GetHit.LifeToPowerMul":0.6,
"Width":640,
"Height":480,
"Super.TargetDefenceMul":1.5,
"LifebarFontScale":1,
"System":"script/main.lua",
"KeyConfig":[{
"Joystick":-1,
"Buttons":["UP","DOWN","LEFT","RIGHT","z","x","c","a","s","d","RETURN","q","w"]
},{
"Joystick":-1,
"Buttons":["t","g","f","h","j","k","l","u","i","o","RSHIFT","LEFTBRACKET","RIGHTBRACKET"]
}],
"JoystickConfig":[{
"Joystick":0,
"Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
},{
"Joystick":1,
"Buttons":["-7","-8","-5","-6","0","1","4","2","3","5","7","6","8"]
}],
"Motif":"data/system.def",
"CommonAir":"data/common.air",
"CommonCmd":"data/common.cmd",
"SFLoad":"data/gamesoundfont.sf2"
"SimulMode":true,
"LifeMul":100,
"Team1VS2Life":120,
"TurnsRecoveryRate":300,
"ZoomActive":false,
"ZoomMin":0.75,
"ZoomMax":1.1,
"ZoomSpeed":1,
"RoundTime":99,
"NumTurns":4,
"NumSimul":4,
"NumTag":4,
"Difficulty":8,
"Credits":10,
"ListenPort":7500,
"ContSelection":true,
"AIRandomColor":true,
"AIRamping":true,
"AutoGuard":false,
"TeamPowerShare":false,
"TeamLifeShare":false,
"Fullscreen":false,
"AudioDucking":false,
"QuickLaunch":0,
"AllowDebugKeys":true,
"PostProcessingShader": 0,
"LocalcoordScalingType": 1,
"IP":{
}
}
`, "\n"), "\r\n"))
tmp := struct {
HelperMax int32
PlayerProjectileMax int
ExplodMax int
AfterImageMax int32
MasterVolume int
WavVolume int
BgmVolume int
Attack_LifeToPowerMul float32 `json:"Attack.LifeToPowerMul"`
GetHit_LifeToPowerMul float32 `json:"GetHit.LifeToPowerMul"`
Width int32
Height int32
Super_TargetDefenceMul float32 `json:"Super.TargetDefenceMul"`
LifebarFontScale float32
System string
KeyConfig []struct {
Joystick int
Buttons []interface{}
}
JoystickConfig []struct {
Joystick int
Buttons []interface{}
}
NumTag int
TeamLifeShare bool
AIRandomColor bool
Fullscreen bool
AudioDucking bool
AllowDebugKeys bool
PostProcessingShader int32
LocalcoordScalingType int32
CommonAir string
CommonCmd string
QuickLaunch int
}{}
chk(json.Unmarshal(defcfg, &tmp))
const configFile = "data/config.json"
if bytes, err := ioutil.ReadFile(configFile); err != nil {
f, err := os.Create(configFile)
chk(err)
f.Write(defcfg)
chk(f.Close())
} else {
if len(bytes) >= 3 &&
bytes[0] == 0xef && bytes[1] == 0xbb && bytes[2] == 0xbf {
bytes = bytes[3:]
}
chk(json.Unmarshal(bytes, &tmp))
}
sys.helperMax = tmp.HelperMax
sys.playerProjectileMax = tmp.PlayerProjectileMax
sys.explodMax = tmp.ExplodMax
sys.afterImageMax = tmp.AfterImageMax
sys.attack_LifeToPowerMul = tmp.Attack_LifeToPowerMul
sys.getHit_LifeToPowerMul = tmp.GetHit_LifeToPowerMul
sys.super_TargetDefenceMul = tmp.Super_TargetDefenceMul
sys.lifebarFontScale = tmp.LifebarFontScale
sys.quickLaunch = tmp.QuickLaunch
sys.masterVolume = tmp.MasterVolume
sys.wavVolume = tmp.WavVolume
sys.bgmVolume = tmp.BgmVolume
sys.AudioDucking = tmp.AudioDucking
stoki := func(key string) int {
return int(StringToKey(key))
}
Atoi := func(key string) int {
var i int
i, _ = strconv.Atoi(key)
return i
}
for a := 0; a < tmp.NumTag; a++ {
for _, kc := range tmp.KeyConfig {
b := kc.Buttons
if kc.Joystick < 0 {
sys.keyConfig = append(sys.keyConfig, KeyConfig{kc.Joystick,
stoki(b[0].(string)), stoki(b[1].(string)),
stoki(b[2].(string)), stoki(b[3].(string)),
stoki(b[4].(string)), stoki(b[5].(string)), stoki(b[6].(string)),
stoki(b[7].(string)), stoki(b[8].(string)), stoki(b[9].(string)),
stoki(b[10].(string)), stoki(b[11].(string)), stoki(b[12].(string))})
}
}
for _, jc := range tmp.JoystickConfig {
b := jc.Buttons
if jc.Joystick >= 0 {
sys.JoystickConfig = append(sys.JoystickConfig, KeyConfig{jc.Joystick,
Atoi(b[0].(string)), Atoi(b[1].(string)),
Atoi(b[2].(string)), Atoi(b[3].(string)),
Atoi(b[4].(string)), Atoi(b[5].(string)), Atoi(b[6].(string)),
Atoi(b[7].(string)), Atoi(b[8].(string)), Atoi(b[9].(string)),
Atoi(b[10].(string)), Atoi(b[11].(string)), Atoi(b[12].(string))})
}
}
}
sys.teamLifeShare = tmp.TeamLifeShare
sys.fullscreen = tmp.Fullscreen
sys.PostProcessingShader = tmp.PostProcessingShader
sys.LocalcoordScalingType = tmp.LocalcoordScalingType
sys.aiRandomColor = tmp.AIRandomColor
sys.allowDebugKeys = tmp.AllowDebugKeys
air, err := ioutil.ReadFile(tmp.CommonAir)
if err != nil {
fmt.Print(err)
}
sys.commonAir = string("\n") + string(air)
cmd, err := ioutil.ReadFile(tmp.CommonCmd)
if err != nil {
fmt.Print(err)
}
sys.commonCmd = string("\n") + string(cmd)
//os.Mkdir("debug", os.ModeSticky|0755)
log := createLog("Ikemen.txt")
defer closeLog(log)
l := sys.init(tmp.Width, tmp.Height)
if err := l.DoFile(tmp.System); err != nil {
fmt.Fprintln(log, err)
switch err.(type) {
case *lua.ApiError:
errstr := strings.Split(err.Error(), "\n")[0]
if len(errstr) < 10 || errstr[len(errstr)-10:] != "<game end>" {
panic(err)
}
default:
panic(err)
}
}
if !sys.gameEnd {
sys.gameEnd = true
}
<-sys.audioClose