summaryrefslogtreecommitdiff
path: root/orkbasecxx/TapeProcessor.cpp
blob: 76c94cf44e16f0be77308952258cd0702fea7dd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Oreka -- A media capture and retrieval platform
 * 
 * Copyright (C) 2005, orecx LLC
 *
 * http://www.orecx.com
 *
 * This program is free software, distributed under the terms of
 * the GNU General Public License.
 * Please refer to http://www.gnu.org/copyleft/gpl.html
 *
 */

#pragma warning( disable: 4786 )

#define _WINSOCKAPI_		// prevents the inclusion of winsock.h

#include "ConfigManager.h"
#include <log4cxx/logger.h>
#include "TapeProcessor.h"

using namespace log4cxx;

TapeProcessor::TapeProcessor()
{
	;
}

void TapeProcessor::SetNextProcessor(TapeProcessorRef& nextProcessor)
{
	m_nextProcessor = nextProcessor;
}

void TapeProcessor::RunNextProcessor(AudioTapeRef& tape)
{
	if(m_nextProcessor.get())
	{
		m_nextProcessor->AddAudioTape(tape);
	}
}


//=====================================================
LoggerPtr s_log;

TapeProcessorRegistry::TapeProcessorRegistry()
{
	s_log = Logger::getLogger("tape.taperegistry");
}


void TapeProcessorRegistry::RegisterTapeProcessor(TapeProcessorRef& tapeProcessor) 
{
	m_TapeProcessors.push_back(tapeProcessor);
	LOG4CXX_INFO(s_log, CStdString("Registered processor: ") + tapeProcessor->GetName());
}


TapeProcessorRef TapeProcessorRegistry::GetNewTapeProcessor(CStdString& TapeProcessorName)
{
	for(std::list<TapeProcessorRef>::iterator it = m_TapeProcessors.begin(); it!=m_TapeProcessors.end(); it++)
	{
		TapeProcessorRef TapeProcessor = *it;

		if(	TapeProcessor->GetName().CompareNoCase(TapeProcessorName) == 0 ) 
		{
			return TapeProcessor->Instanciate();
		}
	}
	return TapeProcessorRef();	// No TapeProcessor found
}

TapeProcessorRegistry* TapeProcessorRegistry::m_singleton = 0;

TapeProcessorRegistry* TapeProcessorRegistry::instance()
{
	if(m_singleton == NULL)
	{
		m_singleton = new TapeProcessorRegistry();
	}
	return m_singleton;
}

void TapeProcessorRegistry::CreateProcessingChain()
{
	TapeProcessorRef previousProcessor;

	//ConfigManager* cm = ConfigManagerSingleton::instance();

	for(std::list<CStdString>::iterator it = CONFIG.m_tapeProcessors.begin(); it != CONFIG.m_tapeProcessors.end(); it++)
	{
		CStdString tapeProcessorName = *it;
		TapeProcessorRef processor = GetNewTapeProcessor(tapeProcessorName);
		if(processor.get())
		{
			if(m_firstTapeProcessor.get() == NULL)
			{
				m_firstTapeProcessor = processor;
			}
			if(previousProcessor.get())
			{
				previousProcessor->SetNextProcessor(processor);
			}
			previousProcessor = processor;
			LOG4CXX_DEBUG(s_log, CStdString("Adding processor to chain:") + tapeProcessorName);
		}
		else
		{
			LOG4CXX_ERROR(s_log, CStdString("Processor:") + tapeProcessorName + " does not exist, please check <TapeProcessors> in config.xml");
		}
	}
}

void TapeProcessorRegistry::RunProcessingChain(AudioTapeRef& tape)
{
	if(m_firstTapeProcessor.get())
	{
		m_firstTapeProcessor->AddAudioTape(tape);
	}
}