void Note2midi::send_noteon (int pitch, int velo) { // smpl_t mpitch = pitch; smpl_t mpitch = floor (aubio_freqtomidi (pitch) + .5); note.event.body.size = 3; note.event.body.type = map->map(map->handle, LV2_MIDI__MidiEvent); note.event.time.frames = counter; note.msg[2] = velo; note.msg[1] = mpitch; if (velo == 0) { printf("off "); note.msg[0] = 0x80; /* note off */ } else{ printf("on "); note.msg[0] = 0x90; /* note on */ } printf("FREQ :%i\n", pitch); printf("MIDI :%f\n\n", mpitch); lv2_atom_sequence_append_event(this->out, out_capacity, ¬e.event); }
/** This plugin does a bit more work in instantiate() than the previous examples. The tempo updates from the host contain several URIs, so those are mapped, and the sine wave to be played needs to be generated based on the current sample rate. */ static LV2_Handle instantiate(const LV2_Descriptor* descriptor, double rate, const char* path, const LV2_Feature* const* features) { Metro* self = (Metro*)calloc(1, sizeof(Metro)); if (!self) { return NULL; } // Scan host features for URID map LV2_URID_Map* map = NULL; for (int i = 0; features[i]; ++i) { if (!strcmp(features[i]->URI, LV2_URID_URI "#map")) { map = (LV2_URID_Map*)features[i]->data; } } if (!map) { fprintf(stderr, "Host does not support urid:map.\n"); free(self); return NULL; } // Map URIS MetroURIs* const uris = &self->uris; self->map = map; uris->atom_Blank = map->map(map->handle, LV2_ATOM__Blank); uris->atom_Float = map->map(map->handle, LV2_ATOM__Float); uris->atom_Object = map->map(map->handle, LV2_ATOM__Object); uris->atom_Path = map->map(map->handle, LV2_ATOM__Path); uris->atom_Resource = map->map(map->handle, LV2_ATOM__Resource); uris->atom_Sequence = map->map(map->handle, LV2_ATOM__Sequence); uris->time_Position = map->map(map->handle, LV2_TIME__Position); uris->time_barBeat = map->map(map->handle, LV2_TIME__barBeat); uris->time_beatsPerMinute = map->map(map->handle, LV2_TIME__beatsPerMinute); uris->time_speed = map->map(map->handle, LV2_TIME__speed); // Initialise instance fields self->rate = rate; self->bpm = 120.0f; self->attack_len = (uint32_t)(attack_s * rate); self->decay_len = (uint32_t)(decay_s * rate); self->state = STATE_OFF; // Generate one cycle of a sine wave at the desired frequency const double freq = 440.0 * 2.0; const double amp = 0.5; self->wave_len = (uint32_t)(rate / freq); self->wave = (float*)malloc(self->wave_len * sizeof(float)); for (uint32_t i = 0; i < self->wave_len; ++i) { self->wave[i] = (float)(sin(i * 2 * M_PI * freq / rate) * amp); } return (LV2_Handle)self; }
EAPI_MAIN int elm_main(int argc, char **argv) { static prog_t handle; bin_t *bin = &handle.bin; handle.server_name = NULL; handle.session_id = NULL; handle.seq_size = SEQ_SIZE; bin->has_gui = true; fprintf(stderr, "Synthpod "SYNTHPOD_VERSION"\n" "Copyright (c) 2015 Hanspeter Portner ([email protected])\n" "Released under Artistic License 2.0 by Open Music Kontrollers\n"); int c; while((c = getopt(argc, argv, "vhgGn:u:s:")) != -1) { switch(c) { case 'v': fprintf(stderr, "--------------------------------------------------------------------\n" "This is free software: you can redistribute it and/or modify\n" "it under the terms of the Artistic License 2.0 as published by\n" "The Perl Foundation.\n" "\n" "This source is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" "Artistic License 2.0 for more details.\n" "\n" "You should have received a copy of the Artistic License 2.0\n" "along the source as a COPYING file. If not, obtain it from\n" "http://www.perlfoundation.org/artistic_license_2_0.\n\n"); return 0; case 'h': fprintf(stderr, "--------------------------------------------------------------------\n" "USAGE\n" " %s [OPTIONS] [BUNDLE_PATH]\n" "\n" "OPTIONS\n" " [-v] print version and full license information\n" " [-h] print usage information\n" " [-g] enable GUI (default)\n" " [-G] disable GUI\n" " [-n] server-name connect to named JACK daemon\n" " [-u] client-uuid client UUID for JACK session management\n" " [-s] sequence-size minimum sequence size (8192)\n\n" , argv[0]); return 0; case 'g': bin->has_gui = true; break; case 'G': bin->has_gui = false; break; case 'n': handle.server_name = optarg; break; case 'u': handle.session_id = optarg; break; case 's': handle.seq_size = MAX(SEQ_SIZE, atoi(optarg)); break; case '?': if( (optopt == 'n') || (optopt == 'u') || (optopt == 's') ) fprintf(stderr, "Option `-%c' requires an argument.\n", optopt); else if(isprint(optopt)) fprintf(stderr, "Unknown option `-%c'.\n", optopt); else fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt); return -1; default: return -1; } } bin_init(bin); LV2_URID_Map *map = ext_urid_map_get(bin->ext_urid); lv2_atom_forge_init(&handle.forge, map); osc_forge_init(&handle.oforge, map); handle.midi_MidiEvent = map->map(map->handle, LV2_MIDI__MidiEvent); handle.time_position = map->map(map->handle, LV2_TIME__Position); handle.time_barBeat = map->map(map->handle, LV2_TIME__barBeat); handle.time_bar = map->map(map->handle, LV2_TIME__bar); handle.time_beatUnit = map->map(map->handle, LV2_TIME__beatUnit); handle.time_beatsPerBar = map->map(map->handle, LV2_TIME__beatsPerBar); handle.time_beatsPerMinute = map->map(map->handle, LV2_TIME__beatsPerMinute); handle.time_frame = map->map(map->handle, LV2_TIME__frame); handle.time_framesPerSecond = map->map(map->handle, LV2_TIME__framesPerSecond); handle.time_speed = map->map(map->handle, LV2_TIME__speed); bin->app_driver.system_port_add = _system_port_add; bin->app_driver.system_port_del = _system_port_del; #if defined(JACK_HAS_CYCLE_TIMES) handle.osc_sched.osc2frames = _osc_schedule_osc2frames; handle.osc_sched.frames2osc = _osc_schedule_frames2osc; handle.osc_sched.handle = &handle; bin->app_driver.osc_sched = &handle.osc_sched; #else bin->app_driver.osc_sched = NULL; #endif bin->app_driver.features = SP_APP_FEATURE_POWER_OF_2_BLOCK_LENGTH; // always true for JACK bin->ui_driver.saved = _ui_saved; bin->ui_driver.features = SP_UI_FEATURE_NEW | SP_UI_FEATURE_SAVE | SP_UI_FEATURE_CLOSE; if(synthpod_nsm_managed() || handle.session_id) bin->ui_driver.features |= SP_UI_FEATURE_IMPORT_FROM | SP_UI_FEATURE_EXPORT_TO; else bin->ui_driver.features |= SP_UI_FEATURE_OPEN | SP_UI_FEATURE_SAVE_AS; // run bin_run(bin, argv, &nsm_driver); // stop bin_stop(bin); // deinit JACK _jack_deinit(&handle); // deinit bin_deinit(bin); return 0; }