Example #1
0
void
configfile::line_after( ifstream *a_file, string a_tag)
{
    /* run to start */
    a_file->clear();
    a_file->seekg( 0, ios::beg );

    a_file->getline( m_line, sizeof(m_line) );
    while ( strncmp( m_line, a_tag.c_str(), a_tag.length()) != 0  &&
            !a_file->eof() )
    {
        a_file->getline( m_line, sizeof(m_line) );
    }
    next_data_line( a_file );
}
Example #2
0
bool
configfile::line_after (std::ifstream & file, const std::string & tag)
{
    bool result = false;
    file.clear();
    file.seekg(0, std::ios::beg);
    file.getline(m_line, sizeof(m_line));
    while (! file.eof())
    {
        result = strncmp(m_line, tag.c_str(), tag.length()) == 0;
        if (result)
            break;
        else
            file.getline(m_line, sizeof(m_line));
    }
    (void) next_data_line(file);
    return result;
}
Example #3
0
bool
userfile::parse (perform & /* a_perf */)
{
    std::ifstream file(m_name.c_str(), std::ios::in | std::ios::ate);
    if (! file.is_open())
    {
        fprintf(stderr, "? error opening [%s]\n", m_name.c_str());
        return false;
    }
    file.seekg(0, std::ios::beg);                       /* seek to start */
    line_after(file, "[user-midi-bus-definitions]");    /* find the tag  */
    int buses = 0;
    sscanf(m_line, "%d", &buses);                       /* atavistic!    */
    for (int bus = 0; bus < buses; ++bus)
    {
        std::string label = make_section_name("user-midi-bus", bus);
        line_after(file, label);
        if (g_user_settings.add_bus(m_line))
        {
            next_data_line(file);
            int instruments = 0;
            int instrument;
            int channel;
            sscanf(m_line, "%d", &instruments);
            for (int j = 0; j < instruments; j++)
            {
                next_data_line(file);
                sscanf(m_line, "%d %d", &channel, &instrument);
                g_user_settings.set_bus_instrument(bus, channel, instrument);
            }
        }
        else
        {
            fprintf
            (
                stderr, "? error adding %s (line = '%s')\n",
                label.c_str(), m_line
            );
        }
    }

    line_after(file, "[user-instrument-definitions]");
    int instruments = 0;
    sscanf(m_line, "%d", &instruments);
    for (int i = 0; i < instruments; i++)
    {
        std::string label = make_section_name("user-instrument", i);
        line_after(file, label);
        if (g_user_settings.add_instrument(m_line))
        {
            next_data_line(file);
            char ccname[SEQ64_LINE_MAX];
            int ccs = 0;
            sscanf(m_line, "%d", &ccs);
            for (int j = 0; j < ccs; j++)
            {
                int c = 0;
                next_data_line(file);

                // sscanf(m_line, "%d", &c);
                // sscanf(m_line, "%[^\n]", ccname);

                ccname[0] = 0;                              // clear the buffer
                sscanf(m_line, "%d %[^\n]", &c, ccname);
                if (c >= 0 && c < MIDI_CONTROLLER_MAX)      // 128
                {
                    g_user_settings.set_instrument_controllers
                    (
                        i, c, std::string(ccname), true
                    );
                }
                else
                {
                    fprintf
                    (
                        stderr, "? illegal controller value %d for '%s'\n",
                        c, label.c_str()
                    );
                }
            }
        }
        else
        {
            fprintf
            (
                stderr, "? error adding %s (line = '%s')\n",
                label.c_str(), m_line
            );
        }
    }

    /*
     * TODO: More (new) variables to follow!
     */

    g_user_settings.set_globals();
    dump_setting_summary();
    file.close();
    return true;
}
Example #4
0
bool
userfile::parse (perform & /* a_perf */)
{
    std::ifstream file(m_name.c_str(), std::ios::in | std::ios::ate);
    if (! file.is_open())
    {
        fprintf(stderr, "? error opening [%s]\n", m_name.c_str());
        return false;
    }
    file.seekg(0, std::ios::beg);                       /* seek to start */

    /*
     * Header commentary is skipped during parsing.
     *
     * \change ca 2016-04-04
     *      Next, if we're using the manual or auto ALSA port options
     *      specified in the RC file, we do want to override the ports that
     *      the queries of the ALSA system find.  Otherwise, we might want to
     *      reveal the names obtained by port detection for ALSA, and do not
     *      want to override the names of the ports that are found.
     */

    if (! rc().reveal_alsa_ports())
    {
        /*
         * [user-midi-bus-definitions]
         */

        line_after(file, "[user-midi-bus-definitions]");    /* find the tag  */
        int buses = 0;
        sscanf(m_line, "%d", &buses);                       /* atavistic!    */

        /*
         * [user-midi-bus-x]
         */

        for (int bus = 0; bus < buses; ++bus)
        {
            std::string label = make_section_name("user-midi-bus", bus);
            line_after(file, label);
            if (usr().add_bus(m_line))
            {
                (void) next_data_line(file);
                int instruments = 0;
                int instrument;
                int channel;
                sscanf(m_line, "%d", &instruments);
                for (int j = 0; j < instruments; ++j)
                {
                    (void) next_data_line(file);
                    sscanf(m_line, "%d %d", &channel, &instrument);
                    usr().set_bus_instrument(bus, channel, instrument);
                }
            }
            else
            {
                fprintf
                (
                    stderr, "? error adding %s (line = '%s')\n",
                    label.c_str(), m_line
                );
            }
        }
    }

    /*
     * [user-instrument-definitions]
     */

    line_after(file, "[user-instrument-definitions]");
    int instruments = 0;
    sscanf(m_line, "%d", &instruments);

    /*
     * [user-instrument-x]
     */

    for (int i = 0; i < instruments; ++i)
    {
        std::string label = make_section_name("user-instrument", i);
        line_after(file, label);
        if (usr().add_instrument(m_line))
        {
            char ccname[SEQ64_LINE_MAX];
            int ccs = 0;
            (void) next_data_line(file);
            sscanf(m_line, "%d", &ccs);
            for (int j = 0; j < ccs; ++j)
            {
                int c = 0;
                (void) next_data_line(file);
                ccname[0] = 0;                              // clear the buffer
                sscanf(m_line, "%d %[^\n]", &c, ccname);
                if (c >= 0 && c < SEQ64_MIDI_CONTROLLER_MAX)      // 128
                {
                    usr().set_instrument_controllers
                    (
                        i, c, std::string(ccname), true
                    );
                }
                else
                {
                    fprintf
                    (
                        stderr, "? illegal controller value %d for '%s'\n",
                        c, label.c_str()
                    );
                }
            }
        }
        else
        {
            fprintf
            (
                stderr, "? error adding %s (line = '%s')\n",
                label.c_str(), m_line
            );
        }
    }

    /*
     * [user-interface-settings]
     *
     * These are new items stored in the user file.  Only variables whose
     * effects we can be completely sure of are read from this section, and
     * used, at this time.  More to come.
     */

    if (! rc().legacy_format())
    {
        int scratch = 0;
        line_after(file, "[user-interface-settings]");
        sscanf(m_line, "%d", &scratch);
        usr().grid_style(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().grid_brackets(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().mainwnd_rows(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().mainwnd_cols(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().max_sets(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().mainwid_border(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().mainwid_spacing(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().control_height(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().zoom(scratch);

        /*
         * This boolean affects the behavior of the scale, key, and background
         * sequence features, but their actual values are stored in the MIDI
         * file, not in the "user" configuration file.
         */

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().global_seq_feature(scratch != 0);

        /*
         * The user-interface font is now selectable at run time.  Old versus
         * new font.
         */

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().use_new_font(scratch != 0);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().allow_two_perfedits(scratch != 0);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().perf_h_page_increment(scratch);

        (void) next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().perf_v_page_increment(scratch);

        /*
         *  Here, we start checking the lines, on the theory that these
         *  very new (2016-02-14) items might mess up people who already have
         *  older Sequencer64 "user" configuration files.
         */

        if (next_data_line(file))
        {
            sscanf(m_line, "%d", &scratch);                 /* now an int   */
            usr().progress_bar_colored(scratch);            /* pick a color */
            if (next_data_line(file))
            {
                sscanf(m_line, "%d", &scratch);
                usr().progress_bar_thick(scratch != 0);
            }
            if (next_data_line(file))
            {
                sscanf(m_line, "%d", &scratch);
                if (scratch <= 1)                           /* boolean?     */
                {
                    usr().inverse_colors(scratch != 0);
                    if (next_data_line(file))
                        sscanf(m_line, "%d", &scratch);     /* get redraw   */
                }
                if (scratch < SEQ64_MINIMUM_REDRAW)
                    scratch = SEQ64_MINIMUM_REDRAW;
                else if (scratch > SEQ64_MAXIMUM_REDRAW)
                    scratch = SEQ64_MAXIMUM_REDRAW;

                usr().window_redraw_rate(scratch);
            }
            if (next_data_line(file))
            {
                sscanf(m_line, "%d", &scratch);
                if (scratch <= 1)                           /* boolean?     */
                    usr().use_more_icons(scratch != 0);
            }
        }
        usr().normalize();    /* calculate derived values */
    }
    else
    {
        /*
         * Legacy values.  Compare to user_settings::set_defaults().
         */

        usr().grid_style(0);
        usr().grid_brackets(1);
        usr().mainwnd_rows(4);
        usr().mainwnd_cols(8);
        usr().max_sets(32);
        usr().mainwid_border(0);
        usr().mainwid_spacing(2);
        usr().control_height(0);
        usr().zoom(SEQ64_DEFAULT_ZOOM);
        usr().global_seq_feature(false);
        usr().use_new_font(false);
        usr().allow_two_perfedits(false);
        usr().perf_h_page_increment(1);
        usr().perf_v_page_increment(1);
        usr().progress_bar_colored(0);
        usr().progress_bar_thick(false);
        usr().inverse_colors(false);
        usr().window_redraw_rate(c_redraw_ms);
    }

    /*
     * [user-midi-settings]
     */

    if (! rc().legacy_format())
    {
        line_after(file, "[user-midi-settings]");
        int scratch = 0;
        sscanf(m_line, "%d", &scratch);
        usr().midi_ppqn(scratch);

        next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().midi_beats_per_bar(scratch);

        next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().midi_beats_per_minute(scratch);

        next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().midi_beat_width(scratch);

        next_data_line(file);
        sscanf(m_line, "%d", &scratch);
        usr().midi_buss_override(char(scratch));
    }

    /*
     * We have all of the data.  Close the file.
     */

    dump_setting_summary();
    file.close();                       /* End Of File, EOF, done! */
    return true;
}
Example #5
0
bool
PreferencesFile::parse( MidiPerformance *a_perf )
{
    /* open binary file */
    ifstream file ( m_name.toUtf8().constData(), ios::in | ios::ate );

    if( ! file.is_open() )
        return false;

    /* run to start */
    file.seekg( 0, ios::beg );

    line_after( &file, "[midi-control]" );

    unsigned int sequences = 0;
    sscanf( m_line, "%u", &sequences );
    next_data_line( &file );

    for (unsigned int i = 0; i < sequences; ++i) {

        int sequence = 0;

        sscanf(m_line, "%d [ %d %d %ld %ld %ld %ld ]"
                       " [ %d %d %ld %ld %ld %ld ]"
                       " [ %d %d %ld %ld %ld %ld ]",

               &sequence,

               &a_perf->get_midi_control_toggle(i)->m_active,
               &a_perf->get_midi_control_toggle(i)->m_inverse_active,
               &a_perf->get_midi_control_toggle(i)->m_status,
               &a_perf->get_midi_control_toggle(i)->m_data,
               &a_perf->get_midi_control_toggle(i)->m_min_value,
               &a_perf->get_midi_control_toggle(i)->m_max_value,

               &a_perf->get_midi_control_on(i)->m_active,
               &a_perf->get_midi_control_on(i)->m_inverse_active,
               &a_perf->get_midi_control_on(i)->m_status,
               &a_perf->get_midi_control_on(i)->m_data,
               &a_perf->get_midi_control_on(i)->m_min_value,
               &a_perf->get_midi_control_on(i)->m_max_value,

               &a_perf->get_midi_control_off(i)->m_active,
               &a_perf->get_midi_control_off(i)->m_inverse_active,
               &a_perf->get_midi_control_off(i)->m_status,
               &a_perf->get_midi_control_off(i)->m_data,
               &a_perf->get_midi_control_off(i)->m_min_value,
               &a_perf->get_midi_control_off(i)->m_max_value);

        next_data_line(&file);
    }
    /* group midi control */
    line_after( &file, "[mute-group]");

    int gtrack = 0;
    sscanf( m_line, "%d", &gtrack );
    next_data_line( &file );

    int mtx[cSeqsInBank], j=0;
    for (int i=0; i< cSeqsInBank; i++) {
        a_perf->select_group_mute(j);
        sscanf(m_line, "%d [%d %d %d %d %d %d %d %d]"
                       " [%d %d %d %d %d %d %d %d]"
                       " [%d %d %d %d %d %d %d %d]"
                       " [%d %d %d %d %d %d %d %d]",
               &j,
               &mtx[0], &mtx[1], &mtx[2], &mtx[3],
                &mtx[4], &mtx[5], &mtx[6], &mtx[7],

                &mtx[8], &mtx[9], &mtx[10], &mtx[11],
                &mtx[12], &mtx[13], &mtx[14], &mtx[15],

                &mtx[16], &mtx[17], &mtx[18], &mtx[19],
                &mtx[20], &mtx[21], &mtx[22], &mtx[23],

                &mtx[24], &mtx[25], &mtx[26], &mtx[27],
                &mtx[28], &mtx[29], &mtx[30], &mtx[31]);
        for (int k=0; k< cSeqsInBank; k++) {
            a_perf->set_group_mute_state(k, mtx[k]);
        }
        j++;
        next_data_line( &file );
    }

    line_after( &file, "[midi-clock]" );
    long buses = 0;
    sscanf( m_line, "%ld", &buses );
    next_data_line( &file );

    for ( int i=0; i<buses; ++i ){

        long bus_on, bus;
        sscanf( m_line, "%ld %ld", &bus, &bus_on );
        a_perf->get_master_midi_bus( )->set_clock( bus, (clock_e) bus_on );
        next_data_line( &file );
    }

    //disabled this for the time being.
    //Default key mappings always used
    /*
    line_after( &file, "[keyboard-control]" );
    long keys = 0;
    sscanf( m_line, "%ld", &keys );
    next_data_line( &file );

    //only clear default key bindings
    //if we have replacements
    if (keys > 0)
    {
        a_perf->key_events.clear();

        for ( int i=0; i<keys; ++i )
        {
            long key = 0, seq = 0;
            sscanf( m_line, "%ld %ld", &key, &seq );
            a_perf->set_key_event( key, seq );
            next_data_line( &file );
        }
    }

    line_after( &file, "[keyboard-group]" );
    long groups = 0;
    sscanf( m_line, "%ld", &groups );
    next_data_line( &file );

    if (groups > 0)
    {
        a_perf->key_groups.clear();

        for ( int i=0; i<groups; ++i )
        {
            long key = 0, group = 0;
            sscanf( m_line, "%ld %ld", &key, &group );
            a_perf->set_key_group( key, group );
            next_data_line( &file );
        }
    }

    sscanf( m_line, "%u %u", &a_perf->m_key_bpm_up,
            &a_perf->m_key_bpm_dn );
    next_data_line( &file );
    sscanf( m_line, "%u %u %u", &a_perf->m_key_screenset_up,
            &a_perf->m_key_screenset_dn,
            &a_perf->m_key_set_playing_screenset);


    next_data_line( &file );

    sscanf( m_line, "%u %u %u", &a_perf->m_key_group_on,
            &a_perf->m_key_group_off,
            &a_perf->m_key_group_learn);

    next_data_line( &file );


    sscanf( m_line, "%s %s %s %s %s",
            &a_perf->m_key_replace,
            &a_perf->m_key_queue,
            &a_perf->m_key_snapshot_1,
            &a_perf->m_key_snapshot_2,
            &a_perf->m_key_keep_queue);
    next_data_line( &file );



    int show_key = 0;
    sscanf(m_line, "%d", &show_key);
    a_perf->m_show_ui_sequence_key = (bool) show_key;
    next_data_line( &file );

    sscanf( m_line, "%u", &a_perf->m_key_start );
    next_data_line( &file );

    sscanf( m_line, "%u", &a_perf->m_key_stop );
    */

    line_after( &file, "[jack-transport]" );
    long flag = 0;

    sscanf( m_line, "%ld", &flag );
    global_with_jack_transport = (bool) flag;

    next_data_line( &file );
    sscanf( m_line, "%ld", &flag );
    global_with_jack_master = (bool) flag;

    next_data_line( &file );
    sscanf( m_line, "%ld", &flag );
    global_with_jack_master_cond = (bool) flag;

    line_after( &file, "[midi-input]" );
    buses = 0;
    sscanf( m_line, "%ld", &buses );
    next_data_line( &file );

    for ( int i=0; i<buses; ++i ){

        long bus_on, bus;
        sscanf( m_line, "%ld %ld", &bus, &bus_on );
        a_perf->get_master_midi_bus( )->set_input( bus, (bool) bus_on );
        next_data_line( &file );
    }

    /* midi clock mod */
    long ticks = 64;
    line_after( &file, "[midi-clock-mod-ticks]" );
    sscanf( m_line, "%ld", &ticks );
    MidiBus::set_clock_mod(ticks);

    /* last used dir */
    line_after( &file, "[last-used-dir]" );
    //FIXME: check for a valid path is missing
    if (m_line[0] == '/')
        last_used_dir = m_line;

    /* recent files list */
    line_after( &file, "[recent-files]" );
    for (int c = 0;c<10;c++){
        if (m_line[0]!=EOF){
            recent_files[c] = m_line;
        } else
            recent_files[c] = "";
        next_data_line(&file);
    }

    /* note resume */
    long resume = 0;
    line_after(&file, "[note-resume]");
    sscanf(m_line, "%ld", &resume);
    a_perf->setResumeNoteOns(resume);

    /* key height */
    long keyHeight = 12;
    line_after(&file, "[key-height]");
    sscanf(m_line, "%ld", &keyHeight);
    a_perf->setEditorKeyHeight(keyHeight);


    /* interaction method  */
    long method = 0;
    line_after( &file, "[interaction-method]" );
    sscanf( m_line, "%ld", &method );
    global_interactionmethod = (interaction_method_e)method;

    file.close();

    return true;
}
Example #6
0
bool
userfile::parse( perform *a_perf )
{
    /* open binary file */
    ifstream file ( m_name.c_str(), ios::in | ios::ate );

    if( ! file.is_open() )
        return false;

    /* run to start */
    file.seekg( 0, ios::beg );

    line_after( &file, "[user-midi-bus-definitions]" );
    int buses = 0;
    sscanf( m_line, "%d", &buses );
    char bus_num[4];

    for ( int i=0; i<buses; i++ )
    {
        snprintf(bus_num, sizeof(bus_num), "%d", i);
        line_after( &file, "[user-midi-bus-" + string(bus_num) + "]");
        global_user_midi_bus_definitions[i].alias = m_line;
        next_data_line( &file );
        int instruments=0;
        int instrument;
        int channel;

        sscanf( m_line, "%d", &instruments );
        for ( int j=0; j<instruments; j++ )
        {
            next_data_line( &file );
            sscanf( m_line, "%d %d", &channel, &instrument );
            global_user_midi_bus_definitions[i].instrument[channel] = instrument;
            // printf( "%d %d\n", channel, instrument );
        }
    }

    line_after( &file, "[user-instrument-definitions]" );
    int instruments = 0;
    sscanf( m_line, "%d", &instruments );
    char instrument_num[4];

    for ( int i=0; i<instruments; i++ )
    {
        snprintf(instrument_num, sizeof(instrument_num), "%d", i);
        line_after( &file, "[user-instrument-" + string(instrument_num) + "]");
        global_user_instrument_definitions[i].instrument = m_line;
        // printf( "%d %s\n", i, m_line );
        next_data_line( &file );
        int ccs=0;
        int cc=0;

        char cc_name[1024];

        sscanf( m_line, "%d", &ccs );
        for ( int j=0; j<ccs; j++ )
        {
            next_data_line( &file );
            sscanf( m_line, "%d", &cc );
            sscanf( m_line, "%[^\n]", cc_name );
            global_user_instrument_definitions[i].controllers[cc] = string(cc_name);
            global_user_instrument_definitions[i].controllers_active[cc] = true;
            // printf( "[%d] %s\n", cc, cc_name );
        }
    }

    file.close();

    return true;
}
Example #7
0
bool
optionsfile::parse( perform *a_perf )
{

    /* file size */
    int file_size = 0;

    /* open binary file */
    ifstream file ( m_name.c_str(), ios::in | ios::ate );

    if( ! file.is_open() )
        return false;
    
    file_size = file.tellg();

    /* run to start */
    file.seekg( 0, ios::beg );

    line_after( &file, "[midi-clock]" );
    long buses = 0;
    sscanf( m_line, "%ld", &buses );
    next_data_line( &file );

    for ( int i=0; i<buses; ++i ){

        long bus_on, bus;
        sscanf( m_line, "%ld %ld", &bus, &bus_on );
        a_perf->get_master_midi_bus( )->set_clock( bus, (clock_e) bus_on );
        next_data_line( &file );
    }


    line_after( &file, "[keyboard-control]" );

    sscanf( m_line, "%u", &a_perf->m_key_start );
    next_data_line( &file );

    sscanf( m_line, "%u", &a_perf->m_key_stop );
    next_data_line( &file );

    sscanf( m_line, "%u", &a_perf->m_key_loop );
    next_data_line( &file );

    sscanf( m_line, "%u", &a_perf->m_key_bpm_dn );
    next_data_line( &file );

    sscanf( m_line, "%u", &a_perf->m_key_bpm_up );

    line_after( &file, "[jack-transport]" );
    long flag = 0;
    
    sscanf( m_line, "%ld", &flag );
    global_with_jack_transport = (bool) flag;
    
    next_data_line( &file );
    sscanf( m_line, "%ld", &flag );
    global_with_jack_master = (bool) flag;
    
    next_data_line( &file );
    sscanf( m_line, "%ld", &flag );
    global_with_jack_master_cond = (bool) flag;
    

    line_after( &file, "[midi-input]" );
    buses = 0;
    sscanf( m_line, "%ld", &buses );
    next_data_line( &file );

    for ( int i=0; i<buses; ++i ){

        long bus_on, bus;
        sscanf( m_line, "%ld %ld", &bus, &bus_on );
        a_perf->get_master_midi_bus( )->set_input( bus, (bool) bus_on );
        next_data_line( &file );
    }
    
    /* midi clock mod */
    long ticks = 64;
    line_after( &file, "[midi-clock-mod-ticks]" );
    sscanf( m_line, "%ld", &ticks );
    midibus::set_clock_mod(ticks);


    /* manual alsa ports */
    line_after( &file, "[manual-alsa-ports]" );
    sscanf( m_line, "%ld", &flag );
    global_manual_alsa_ports = (bool) flag;

    /* last used dir */
    line_after( &file, "[last-used-dir]" );
    //FIXME: check for a valid path is missing
    if (m_line[0] == '/')
        last_used_dir.assign(m_line);

    /* interaction method  */
    long method = 0;
    line_after( &file, "[interaction-method]" );
    sscanf( m_line, "%ld", &method );
    global_interactionmethod = (interaction_method_e)method;
    
    file.close();

    return true;
}