void file_info::copy(const file_info & p_source)
{
    if (&p_source != this) {
        copy_meta(p_source);
        copy_info(p_source);
        set_length(p_source.get_length());
        set_replaygain(p_source.get_replaygain());
    }
}
void file_info::_add_tag(const file_info & otherTag) {
	this->set_replaygain( replaygain_info::g_merge( this->get_replaygain(), otherTag.get_replaygain() ) );

	const char * tt1 = this->info_get(_tagtype);
	const char * tt2 = otherTag.info_get(_tagtype);
	if (tt2) {
		if (tt1) {
			this->info_set(_tagtype, PFC_string_formatter() << tt1 << "|" << tt2);
		} else {
			this->info_set(_tagtype, tt2);
		}
	}

}
void file_info::merge_fallback(const file_info & source) {
	set_replaygain( replaygain_info::g_merge(get_replaygain(), source.get_replaygain() ) );
	if (get_length() <= 0) set_length(source.get_length());
	t_size count = source.info_get_count();
	for(t_size infoWalk = 0; infoWalk < count; ++infoWalk) {
		const char * name = source.info_enum_name(infoWalk);
		if (!info_exists(name)) __info_add_unsafe(name, source.info_enum_value(infoWalk));
	}
	count = source.meta_get_count();
	for(t_size metaWalk = 0; metaWalk < count; ++metaWalk) {
		const char * name = source.meta_enum_name(metaWalk);
		if (!meta_exists(name)) _copy_meta_single_nocheck(source, metaWalk);
	}
}
Example #4
0
audio_sample t_replaygain_config::query_scale(const file_info & p_info) const
{
	const audio_sample peak_margin = 1.0;//used to be 0.999 but it must not trigger on lossless

	audio_sample peak = peak_margin;
	audio_sample gain = 0;

	bool have_rg_gain = false, have_rg_peak = false;

	if (m_source_mode == source_mode_track || m_source_mode == source_mode_album)
	{
		replaygain_info info = p_info.get_replaygain();
		float gain_select = replaygain_info::gain_invalid, peak_select = replaygain_info::peak_invalid;
		if (m_source_mode == source_mode_track)
		{
			if (info.is_track_gain_present()) {gain = info.m_track_gain; have_rg_gain = true; }
			else if (info.is_album_gain_present()) {gain = info.m_album_gain; have_rg_gain = true; }
			if (info.is_track_peak_present()) {peak = info.m_track_peak; have_rg_peak = true; }
			else if (info.is_album_peak_present()) {peak = info.m_album_peak; have_rg_peak = true; }
		}
		else
		{
			if (info.is_album_gain_present()) {gain = info.m_album_gain; have_rg_gain = true; }
			else if (info.is_track_gain_present()) {gain = info.m_track_gain; have_rg_gain = true; }
			if (info.is_album_peak_present()) {peak = info.m_album_peak; have_rg_peak = true; }
			else if (info.is_track_peak_present()) {peak = info.m_track_peak; have_rg_peak = true; }
		}
	}

	gain += have_rg_gain ? m_preamp_with_rg : m_preamp_without_rg;

	audio_sample scale = 1.0;

	if (m_processing_mode == processing_mode_gain || m_processing_mode == processing_mode_gain_and_peak)
	{
		scale *= audio_math::gain_to_scale(gain);
	}

	if (m_processing_mode == processing_mode_peak || m_processing_mode == processing_mode_gain_and_peak)
	{
		if (scale * peak > peak_margin)
			scale = (audio_sample)(peak_margin / peak);
	}

	return scale;
}
void file_info_const_impl::copy(const file_info & p_source)
{
//	profiler(file_info_const_impl__copy);
	t_size meta_size = 0;
	t_size info_size = 0;
	t_size valuemap_size = 0;
	t_size stringbuffer_size = 0;
#ifdef __file_info_const_impl_have_hintmap__
	t_size hintmap_size = 0;
#endif

	{
//		profiler(file_info_const_impl__copy__pass1);
		t_size index;
		m_meta_count = pfc::downcast_guarded<t_index>(p_source.meta_get_count());
		meta_size = m_meta_count * sizeof(meta_entry);
#ifdef __file_info_const_impl_have_hintmap__
		hintmap_size = (m_meta_count > hintmap_cutoff) ? m_meta_count * sizeof(t_index) : 0;
#endif//__file_info_const_impl_have_hintmap__
		for(index = 0; index < m_meta_count; index++ )
		{
			{
				const char * name = p_source.meta_enum_name(index);
				if (optimize_fieldname(name) == 0)
					stringbuffer_size += strlen(name) + 1;
			}

			t_size val; const t_size val_max = p_source.meta_enum_value_count(index);
			
			if (val_max == 1)
			{
				stringbuffer_size += strlen(p_source.meta_enum_value(index,0)) + 1;
			}
			else
			{
				valuemap_size += val_max * sizeof(char*);

				for(val = 0; val < val_max; val++ )
				{
					stringbuffer_size += strlen(p_source.meta_enum_value(index,val)) + 1;
				}
			}
		}

		m_info_count = pfc::downcast_guarded<t_index>(p_source.info_get_count());
		info_size = m_info_count * sizeof(info_entry);
		for(index = 0; index < m_info_count; index++ )
		{
			const char * name = p_source.info_enum_name(index);
			if (optimize_infoname(name) == NULL) stringbuffer_size += strlen(name) + 1;
			stringbuffer_size += strlen(p_source.info_enum_value(index)) + 1;
		}
	}


	{
//		profiler(file_info_const_impl__copy__alloc);
		m_buffer.set_size(
#ifdef __file_info_const_impl_have_hintmap__
			hintmap_size + 
#endif
			meta_size + info_size + valuemap_size + stringbuffer_size);
	}

	char * walk = m_buffer.get_ptr();

#ifdef __file_info_const_impl_have_hintmap__
	t_index* hintmap = (hintmap_size > 0) ? (t_index*) walk : NULL;
	walk += hintmap_size;
#endif
	meta_entry * meta = (meta_entry*) walk;
	walk += meta_size;
	char ** valuemap = (char**) walk;
	walk += valuemap_size;
	info_entry * info = (info_entry*) walk;
	walk += info_size;
	char * stringbuffer = walk;

	m_meta = meta;
	m_info = info;
#ifdef __file_info_const_impl_have_hintmap__
	m_hintmap = hintmap;
#endif

	{
//		profiler(file_info_const_impl__copy__pass2);
		t_size index;
		for( index = 0; index < m_meta_count; index ++ )
		{
			t_size val; const t_size val_max = p_source.meta_enum_value_count(index);

			{
				const char * name = p_source.meta_enum_name(index);
				const char * name_opt = optimize_fieldname(name);
				if (name_opt == NULL)
					meta[index].m_name = stringbuffer_append(stringbuffer, name );
				else
					meta[index].m_name = name_opt;
			}
			
			meta[index].m_valuecount = val_max;

			if (val_max == 1)
			{
				meta[index].m_valuemap = reinterpret_cast<const char * const *>(stringbuffer_append(stringbuffer, p_source.meta_enum_value(index,0) ));
			}
			else
			{
				meta[index].m_valuemap = valuemap;
				for( val = 0; val < val_max ; val ++ )
					*(valuemap ++ ) = stringbuffer_append(stringbuffer, p_source.meta_enum_value(index,val) );
			}
		}

		for( index = 0; index < m_info_count; index ++ )
		{
			const char * name = p_source.info_enum_name(index);
			const char * name_opt = optimize_infoname(name);
			if (name_opt == NULL)
				info[index].m_name = stringbuffer_append(stringbuffer, name );
			else
				info[index].m_name = name_opt;
			info[index].m_value = stringbuffer_append(stringbuffer, p_source.info_enum_value(index) );
		}
	}

	m_length = p_source.get_length();
	m_replaygain = p_source.get_replaygain();
#ifdef __file_info_const_impl_have_hintmap__
	if (hintmap != NULL) {
//		profiler(file_info_const_impl__copy__hintmap);
		for(t_size n=0;n<m_meta_count;n++) hintmap[n]=n;
		pfc::sort(sort_callback_hintmap_impl(meta,hintmap),m_meta_count);
	}
#endif//__file_info_const_impl_have_hintmap__
}
Example #6
0
void embeddedcue_metadata_manager::set_track_info(unsigned p_track,file_info const & p_info) {
	track_record * rec = m_content.query_ptr(p_track);
	if (rec == NULL) throw exception_io_data();
	rec->m_info.from_info_set_meta(p_info);
	rec->m_info.set_replaygain(p_info.get_replaygain());
}
void file_info::_set_tag(const file_info & tag) {
	this->copy_meta(tag);
	this->set_replaygain( replaygain_info::g_merge( this->get_replaygain(), tag.get_replaygain() ) );
	const char * tt = tag.info_get(_tagtype);
	if (tt) this->info_set(_tagtype, tt);
}