Ejemplo n.º 1
0
void Alg_smf_write::write_update(Alg_update_ptr update)
{
    char *name = update->parameter.attr_name();

    /****Non-Meta Events****/
    if (!strcmp(name, "pressurer")) {
	    write_delta(update->time);
		if (update->key < 0) { // channel pressure message
		    write_data(0xD0 + to_midi_channel(update->chan));
		    write_data((int)(update->parameter.r * 127));
		} else { // just 1 key -- poly pressure
		    write_data(0xA0 + to_midi_channel(update->chan));
		    write_data(update->key);
		    write_data((int)(update->parameter.r * 127));
		}
	} else if (!strcmp(name, "programi")) {
		write_delta(update->time);
		write_data(0xC0 + to_midi_channel(update->chan));
		write_data(update->parameter.i);
	} else if (!strcmp(name, "bendr")) {
		int temp = ROUND(8192.0 * (update->parameter.r + 1));
		if (temp > 8191) temp = 8191; // 14 bits maximum
		if (temp < 0) temp = 0;
		int c2 = temp & 0x7F; // low 7 bits
		int c1 = temp >> 7;   // high 7 bits
		write_delta(update->time);
		write_data(0xE0 + to_midi_channel(update->chan));
		write_data(c1);
		write_data(c2);
	} else if (!strncmp(name, "control", 7) && 
Ejemplo n.º 2
0
void Alg_smf_write::write_note(Alg_note_ptr note, bool on)
{
	double event_time = (on ? note->time : note->time + note->dur);
    write_delta(event_time);

    //printf("deltaDivisions: %d, beats elapsed: %g, on? %c\n", deltaDivisions, note->time, on);

    int vel = (int) note->loud;
    char chan = (note->chan & 15);
    int pitch = int(note->pitch + 0.5);
    if (pitch < 0) {
  	    pitch = pitch % 12;
    } else if (pitch > 127) {
	    pitch = (pitch % 12) + 120; // put pitch in 10th octave
	    if (pitch > 127) pitch -= 12; // or 9th octave
    }
	// use NOTEON message for note-on, and, if velocity is zero, for note-off
    if (on || vel == 0) {
        putc(0x90 + chan, out_file); // note-on
    } else {
        putc(0x80 + chan, out_file); // note-off with non-zero velocity
	}
    putc(pitch, out_file);
    write_data(vel);
}
Ejemplo n.º 3
0
void Alg_smf_write::write_text(char type, char length, char *s, double event_time)
{
    write_delta(event_time);
    putc(0xFF, out_file);
    putc(type, out_file);
    putc(length, out_file);
    fprintf(out_file, s);
    //printf("Inserted text %s, of length %X, of type: %x.\n", s, length, type);
}
Ejemplo n.º 4
0
        static void write(succinct::bit_vector_builder& bvb,
                          Iterator begin,
                          uint64_t universe, uint64_t n,
                          global_parameters const& params)
        {
            assert(n > 0);
            auto const& conf = configuration::get();

            auto cost_fun = [&](uint64_t universe, uint64_t n) {
                return base_sequence_type::bitsize(params, universe, n) + conf.fix_cost;
            };

            optimal_partition opt(begin, universe, n, cost_fun, conf.eps1, conf.eps2);

            size_t partitions = opt.partition.size();
            assert(partitions > 0);
            assert(opt.partition.front() != 0);
            assert(opt.partition.back() == n);
            write_gamma_nonzero(bvb, partitions);

            std::vector<uint64_t> cur_partition;
            uint64_t cur_base = 0;
            if (partitions == 1) {
                cur_base = *begin;
                Iterator it = begin;

                for (size_t i = 0; i < n; ++i, ++it) {
                    cur_partition.push_back(*it - cur_base);
                }

                uint64_t universe_bits = ceil_log2(universe);
                bvb.append_bits(cur_base, universe_bits);

                // write universe only if non-singleton and not tight
                if (n > 1) {
                    if (cur_base + cur_partition.back() + 1 == universe) {
                        // tight universe
                        write_delta(bvb, 0);
                    } else {
                        write_delta(bvb, cur_partition.back());
                    }
                }

                base_sequence_type::write(bvb, cur_partition.begin(),
                                          cur_partition.back() + 1,
                                          cur_partition.size(),
                                          params);
            } else {
                succinct::bit_vector_builder bv_sequences;
                std::vector<uint64_t> endpoints;
                std::vector<uint64_t> upper_bounds;

                uint64_t cur_i = 0;
                Iterator it = begin;
                cur_base = *begin;
                upper_bounds.push_back(cur_base);

                for (size_t p = 0; p < opt.partition.size(); ++p) {
                    cur_partition.clear();
                    uint64_t value = 0;
                    for (; cur_i < opt.partition[p]; ++cur_i, ++it) {
                        value = *it;
                        cur_partition.push_back(value - cur_base);
                    }

                    uint64_t upper_bound = value;
                    assert(cur_partition.size() > 0);
                    base_sequence_type::write(bv_sequences, cur_partition.begin(),
                                              cur_partition.back() + 1,
                                              cur_partition.size(), // XXX skip last one?
                                              params);
                    endpoints.push_back(bv_sequences.size());
                    upper_bounds.push_back(upper_bound);
                    cur_base = upper_bound + 1;
                }

                succinct::bit_vector_builder bv_sizes;
                compact_elias_fano::write(bv_sizes, opt.partition.begin(),
                                          n, partitions - 1,
                                          params);

                succinct::bit_vector_builder bv_upper_bounds;
                compact_elias_fano::write(bv_upper_bounds, upper_bounds.begin(),
                                          universe, partitions + 1,
                                          params);

                uint64_t endpoint_bits = ceil_log2(bv_sequences.size() + 1);
                write_gamma(bvb, endpoint_bits);

                bvb.append(bv_sizes);
                bvb.append(bv_upper_bounds);

                for (uint64_t p = 0; p < endpoints.size() - 1; ++p) {
                    bvb.append_bits(endpoints[p], endpoint_bits);
                }

                bvb.append(bv_sequences);
            }
        }