From 07d94b9b4868fad26c9e8ac2ae4901849a09b8ac Mon Sep 17 00:00:00 2001 From: John Emmas Date: Sun, 4 Aug 2013 15:17:19 +0100 Subject: [PATCH] 'libs/ardour' - Use 'std::vector' instead of dynamically sized arrays (required to be buildable with MSVC) --- libs/ardour/broadcast_info.cc | 7 ++++--- libs/ardour/export_graph_builder.cc | 8 +++++--- libs/ardour/io.cc | 19 ++++++++++--------- libs/ardour/ladspa_plugin.cc | 4 ++-- libs/ardour/lv2_plugin.cc | 20 ++++++++++---------- libs/ardour/region_factory.cc | 8 ++++---- libs/ardour/sndfilesource.cc | 6 +++--- 7 files changed, 38 insertions(+), 34 deletions(-) diff --git a/libs/ardour/broadcast_info.cc b/libs/ardour/broadcast_info.cc index 78c6132f85..a08d2c7991 100644 --- a/libs/ardour/broadcast_info.cc +++ b/libs/ardour/broadcast_info.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -37,15 +38,15 @@ namespace ARDOUR static void snprintf_bounded_null_filled (char* target, size_t target_size, char const * fmt, ...) { - char buf[target_size+1]; + std::vector buf(target_size+1); va_list ap; va_start (ap, fmt); - vsnprintf (buf, target_size+1, fmt, ap); + vsnprintf (&buf[0], target_size+1, fmt, ap); va_end (ap); memset (target, 0, target_size); - memcpy (target, buf, target_size); + memcpy (target, &buf[0], target_size); } diff --git a/libs/ardour/export_graph_builder.cc b/libs/ardour/export_graph_builder.cc index c7875c0b9b..127546e8fc 100644 --- a/libs/ardour/export_graph_builder.cc +++ b/libs/ardour/export_graph_builder.cc @@ -20,6 +20,8 @@ #include "ardour/export_graph_builder.h" +#include + #include #include "audiographer/process_context.h" @@ -317,8 +319,8 @@ ExportGraphBuilder::Normalizer::Normalizer (ExportGraphBuilder & parent, FileSpe { std::string tmpfile_path = parent.session.session_directory().export_path(); tmpfile_path = Glib::build_filename(tmpfile_path, "XXXXXX"); - char tmpfile_path_buf[tmpfile_path.size() + 1]; - std::copy(tmpfile_path.begin(), tmpfile_path.end(), tmpfile_path_buf); + std::vector tmpfile_path_buf(tmpfile_path.size() + 1); + std::copy(tmpfile_path.begin(), tmpfile_path.end(), tmpfile_path_buf.begin()); tmpfile_path_buf[tmpfile_path.size()] = '\0'; config = new_config; @@ -334,7 +336,7 @@ ExportGraphBuilder::Normalizer::Normalizer (ExportGraphBuilder & parent, FileSpe normalizer->add_output (threader); int format = ExportFormatBase::F_RAW | ExportFormatBase::SF_Float; - tmp_file.reset (new TmpFile (tmpfile_path_buf, format, channels, config.format->sample_rate())); + tmp_file.reset (new TmpFile (&tmpfile_path_buf[0], format, channels, config.format->sample_rate())); tmp_file->FileWritten.connect_same_thread (post_processing_connection, boost::bind (&Normalizer::start_post_processing, this)); diff --git a/libs/ardour/io.cc b/libs/ardour/io.cc index 1349d49a0c..4498e4fbd8 100644 --- a/libs/ardour/io.cc +++ b/libs/ardour/io.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -1379,20 +1380,20 @@ IO::build_legal_port_name (DataType type) limit = name_size - _session.engine().client_name().length() - (suffix.length() + 5); - char buf1[name_size+1]; - char buf2[name_size+1]; + std::vector buf1(name_size+1); + std::vector buf2(name_size+1); /* colons are illegal in port names, so fix that */ string nom = _name.val(); replace_all (nom, ":", ";"); - snprintf (buf1, name_size+1, ("%.*s/%s"), limit, nom.c_str(), suffix.c_str()); + snprintf (&buf1[0], name_size+1, ("%.*s/%s"), limit, nom.c_str(), suffix.c_str()); - int port_number = find_port_hole (buf1); - snprintf (buf2, name_size+1, "%s %d", buf1, port_number); + int port_number = find_port_hole (&buf1[0]); + snprintf (&buf2[0], name_size+1, "%s %d", buf1, port_number); - return string (buf2); + return string (&buf2[0]); } int32_t @@ -1410,13 +1411,13 @@ IO::find_port_hole (const char* base) */ for (n = 1; n < 9999; ++n) { - char buf[jack_port_name_size()]; + std::vector buf(jack_port_name_size()); PortSet::iterator i = _ports.begin(); - snprintf (buf, jack_port_name_size(), _("%s %u"), base, n); + snprintf (&buf[0], jack_port_name_size(), _("%s %u"), base, n); for ( ; i != _ports.end(); ++i) { - if (i->name() == buf) { + if (string(i->name()) == string(&buf[0])) { break; } } diff --git a/libs/ardour/ladspa_plugin.cc b/libs/ardour/ladspa_plugin.cc index 38d0d8b944..c78d8a28dd 100644 --- a/libs/ardour/ladspa_plugin.cc +++ b/libs/ardour/ladspa_plugin.cc @@ -919,8 +919,8 @@ LadspaPlugin::do_save_preset (string name) lrdf_defaults defaults; defaults.count = input_parameter_pids.size (); - lrdf_portvalue portvalues[input_parameter_pids.size()]; - defaults.items = portvalues; + std::vector portvalues(input_parameter_pids.size()); + defaults.items = &portvalues[0]; for (vector::size_type i = 0; i < input_parameter_pids.size(); ++i) { portvalues[i].pid = input_parameter_pids[i]; diff --git a/libs/ardour/lv2_plugin.cc b/libs/ardour/lv2_plugin.cc index 04012a7ada..4f1f9b9677 100644 --- a/libs/ardour/lv2_plugin.cc +++ b/libs/ardour/lv2_plugin.cc @@ -1119,16 +1119,16 @@ LV2Plugin::write_to(RingBuffer* dest, uint32_t size, const uint8_t* body) { - const uint32_t buf_size = sizeof(UIMessage) + size; - uint8_t buf[buf_size]; + const uint32_t buf_size = sizeof(UIMessage) + size; + vector buf(buf_size); - UIMessage* msg = (UIMessage*)buf; + UIMessage* msg = (UIMessage*)&buf[0]; msg->index = index; msg->protocol = protocol; msg->size = size; memcpy(msg + 1, body, size); - return (dest->write(buf, buf_size) == buf_size); + return (dest->write(&buf[0], buf_size) == buf_size); } bool @@ -1185,13 +1185,13 @@ LV2Plugin::emit_to_ui(void* controller, UIMessageSink sink) error << "Error reading from Plugin=>UI RingBuffer" << endmsg; break; } - uint8_t body[msg.size]; - if (_to_ui->read(body, msg.size) != msg.size) { + vector body(msg.size); + if (_to_ui->read(&body[0], msg.size) != msg.size) { error << "Error reading from Plugin=>UI RingBuffer" << endmsg; break; } - sink(controller, msg.index, msg.size, msg.protocol, body); + sink(controller, msg.index, msg.size, msg.protocol, &body[0]); read_space -= sizeof(msg) + msg.size; } @@ -1671,15 +1671,15 @@ LV2Plugin::connect_and_run(BufferSet& bufs, error << "Error reading from UI=>Plugin RingBuffer" << endmsg; break; } - uint8_t body[msg.size]; - if (_from_ui->read(body, msg.size) != msg.size) { + vector body(msg.size); + if (_from_ui->read(&body[0], msg.size) != msg.size) { error << "Error reading from UI=>Plugin RingBuffer" << endmsg; break; } if (msg.protocol == urids.atom_eventTransfer) { LV2_Evbuf* buf = _ev_buffers[msg.index]; LV2_Evbuf_Iterator i = lv2_evbuf_end(buf); - const LV2_Atom* const atom = (const LV2_Atom*)body; + const LV2_Atom* const atom = (const LV2_Atom*)&body[0]; if (!lv2_evbuf_write(&i, nframes, 0, atom->type, atom->size, (const uint8_t*)(atom + 1))) { error << "Failed to write data to LV2 event buffer\n"; diff --git a/libs/ardour/region_factory.cc b/libs/ardour/region_factory.cc index 3e81524750..44f8c34ddd 100644 --- a/libs/ardour/region_factory.cc +++ b/libs/ardour/region_factory.cc @@ -564,7 +564,7 @@ RegionFactory::new_region_name (string old) uint32_t number; string::size_type len = old.length() + 64; string remainder; - char buf[len]; + std::vector buf(len); if ((last_period = old.find_last_of ('.')) == string::npos) { @@ -603,8 +603,8 @@ RegionFactory::new_region_name (string old) number++; - snprintf (buf, len, "%s%" PRIu32 "%s", old.substr (0, last_period + 1).c_str(), number, remainder.c_str()); - sbuf = buf; + snprintf (&buf[0], len, "%s%" PRIu32 "%s", old.substr (0, last_period + 1).c_str(), number, remainder.c_str()); + sbuf = &buf[0]; if (region_name_map.find (sbuf) == region_name_map.end ()) { break; @@ -612,7 +612,7 @@ RegionFactory::new_region_name (string old) } if (number != (UINT_MAX-1)) { - return buf; + return &buf[0]; } error << string_compose (_("cannot create new name for region \"%1\""), old) << endmsg; diff --git a/libs/ardour/sndfilesource.cc b/libs/ardour/sndfilesource.cc index f29682aeaa..2aae84085a 100644 --- a/libs/ardour/sndfilesource.cc +++ b/libs/ardour/sndfilesource.cc @@ -766,12 +766,12 @@ SndFileSource::crossfade (Sample* data, framecnt_t cnt, int fade_in) } else if (xfade < xfade_frames) { - gain_t in[xfade]; - gain_t out[xfade]; + std::vector in(xfade); + std::vector out(xfade); /* short xfade, compute custom curve */ - compute_equal_power_fades (xfade, in, out); + compute_equal_power_fades (xfade, &in[0], &out[0]); for (framecnt_t n = 0; n < xfade; ++n) { xfade_buf[n] = (xfade_buf[n] * out[n]) + (fade_data[n] * in[n]);