aboutsummaryrefslogtreecommitdiff
path: root/audio/lmms/02-stutter_audio.patch
blob: 65c9563996be5def914d3e9c506666f6aefbbe3a (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
From 9db67dd1aa1a4326821f17ddddfc73c198aa3f52 Mon Sep 17 00:00:00 2001
From: Groboclown <matt@groboclown.net>
Date: Thu, 27 Jun 2013 14:15:59 -0500
Subject: [PATCH 1/2] Add new feature to the audio file processor which allows
 for resuming playback of the sample on a new note from where the last note
 played.

---
diff -Nur lmms-0.4.15/include/sample_buffer.h lmms-0.4.15.new/include/sample_buffer.h
--- lmms-0.4.15/include/sample_buffer.h	2013-06-11 20:57:16.000000000 +0000
+++ lmms-0.4.15.new/include/sample_buffer.h	2013-06-29 22:41:39.322810181 +0000
@@ -51,6 +51,15 @@
 	public:
 		handleState( bool _varying_pitch = false );
 		virtual ~handleState();
+		inline const f_cnt_t frameIndex() const
+		{
+		    return m_frameIndex;
+		}
+
+		inline void setFrameIndex( f_cnt_t _index )
+		{
+		    m_frameIndex = _index;
+		}
 
 
 	private:
diff -Nur lmms-0.4.15/plugins/audio_file_processor/audio_file_processor.cpp lmms-0.4.15.new/plugins/audio_file_processor/audio_file_processor.cpp
--- lmms-0.4.15/plugins/audio_file_processor/audio_file_processor.cpp	2013-06-11 20:57:16.000000000 +0000
+++ lmms-0.4.15.new/plugins/audio_file_processor/audio_file_processor.cpp	2013-06-29 22:41:39.322810181 +0000
@@ -75,7 +75,9 @@
 	m_startPointModel( 0, 0, 1, 0.0000001f, this, tr( "Start of sample") ),
 	m_endPointModel( 1, 0, 1, 0.0000001f, this, tr( "End of sample" ) ),
 	m_reverseModel( false, this, tr( "Reverse sample" ) ),
-	m_loopModel( false, this, tr( "Loop") )
+	m_loopModel( false, this, tr( "Loop") ),
+	m_stutterModel( false, this, tr( "Stutter" ) ),
+	m_nextPlayStartPoint( 0 )
 {
 	connect( &m_reverseModel, SIGNAL( dataChanged() ),
 				this, SLOT( reverseModelChanged() ) );
@@ -85,6 +87,8 @@
 				this, SLOT( loopPointChanged() ) );
 	connect( &m_endPointModel, SIGNAL( dataChanged() ),
 				this, SLOT( loopPointChanged() ) );
+	connect( &m_stutterModel, SIGNAL( dataChanged() ),
+				this, SLOT( stutterModelChanged() ) ); 	
 }
 
 
@@ -102,10 +106,27 @@
 {
 	const fpp_t frames = _n->framesLeftForCurrentPeriod();
 
+	// Magic key - a frequency < 20 (say, the bottom piano note if using
+	// a A4 base tuning) restarts the start point. The note is not actually
+	// played.
+	if( m_stutterModel.value() == true && _n->frequency() < 20.0 )
+	{
+		m_nextPlayStartPoint = m_sampleBuffer.startFrame();
+		return;
+	}
+	
 	if( !_n->m_pluginData )
 	{
+		if( m_stutterModel.value() == true && m_nextPlayStartPoint >= m_sampleBuffer.endFrame() )
+		{
+			// Restart playing the note if in stutter mode, not in loop mode,
+			// and we're at the end of the sample.
+			m_nextPlayStartPoint = m_sampleBuffer.startFrame();
+		}
 		_n->m_pluginData = new handleState( _n->hasDetuningInfo() );
+		((handleState *)_n->m_pluginData)->setFrameIndex(m_nextPlayStartPoint);
 	}
+	
 
 	if( m_sampleBuffer.play( _working_buffer,
 					(handleState *)_n->m_pluginData,
@@ -121,6 +142,10 @@
 	{
 		emit isPlaying( 0 );
 	}
+	if( m_stutterModel.value() == true )
+	{
+		m_nextPlayStartPoint = ((handleState *)_n->m_pluginData)->frameIndex();
+	}
 }
 
 
@@ -249,6 +274,10 @@
 }
 
 
+void audioFileProcessor::stutterModelChanged()
+{
+	m_nextPlayStartPoint = m_sampleBuffer.startFrame();
+} 
 
 
 void audioFileProcessor::loopPointChanged( void )
@@ -257,6 +286,7 @@
 						( m_sampleBuffer.frames()-1 ) );
 	const f_cnt_t f2 = static_cast<f_cnt_t>( m_endPointModel.value() *
 						( m_sampleBuffer.frames()-1 ) );
+	m_nextPlayStartPoint = f1;
 	m_sampleBuffer.setStartFrame( qMin<f_cnt_t>( f1, f2 ) );
 	m_sampleBuffer.setEndFrame( qMax<f_cnt_t>( f1, f2 ) );
 	emit dataChanged();
@@ -298,7 +328,7 @@
 
 	m_reverseButton = new pixmapButton( this );
 	m_reverseButton->setCheckable( TRUE );
-	m_reverseButton->move( 184, 124 );
+	m_reverseButton->move( 176, 124 ); // 184
 	m_reverseButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
 							"reverse_on" ) );
 	m_reverseButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
@@ -311,7 +341,7 @@
 
 	m_loopButton = new pixmapButton( this );
 	m_loopButton->setCheckable( TRUE );
-	m_loopButton->move( 220, 124 );
+	m_loopButton->move( 202, 124 ); // 220
 	m_loopButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
 								"loop_on" ) );
 	m_loopButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
@@ -325,6 +355,23 @@
 			"This is useful for things like string and choir "
 			"samples." ) );
 
+	m_stutterButton = new pixmapButton( this );
+	m_stutterButton->setCheckable( true );
+	m_stutterButton->move( 228, 124 );
+	m_stutterButton->setActiveGraphic( PLUGIN_NAME::getIconPixmap(
+								"stutter_on" ) );
+	m_stutterButton->setInactiveGraphic( PLUGIN_NAME::getIconPixmap(
+								"stutter_off" ) );
+	toolTip::add( m_stutterButton,
+				tr( "Continue sample playback across notes" ) );
+	m_stutterButton->setWhatsThis(
+		tr( "Enabling this option makes the sample continue playing "
+			"across different notes - if you change pitch, or the note "
+			"length stops before the end of the sample, then the next "
+			"note played will continue where it left off. To reset the "
+			"playback to the start of the sample, insert a note at the bottom "
+			"of the keyboard (< 20 Hz)") ); 	
+
 	m_ampKnob = new knob( knobStyled, this );
 	m_ampKnob->setVolumeKnob( TRUE );
 	m_ampKnob->move( 17, 108 );
@@ -504,6 +551,7 @@
 	m_endKnob->setModel( &a->m_endPointModel );
 	m_reverseButton->setModel( &a->m_reverseModel );
 	m_loopButton->setModel( &a->m_loopModel );
+	m_stutterButton->setModel( &a->m_stutterModel );
 	sampleUpdated();
 }
 
diff -Nur lmms-0.4.15/plugins/audio_file_processor/audio_file_processor.h lmms-0.4.15.new/plugins/audio_file_processor/audio_file_processor.h
--- lmms-0.4.15/plugins/audio_file_processor/audio_file_processor.h	2013-06-11 20:57:16.000000000 +0000
+++ lmms-0.4.15.new/plugins/audio_file_processor/audio_file_processor.h	2013-06-29 22:41:39.322810181 +0000
@@ -74,6 +74,7 @@
 	void reverseModelChanged();
 	void ampModelChanged();
 	void loopPointChanged();
+	void stutterModelChanged();
 
 
 signals:
@@ -90,6 +91,9 @@
 	FloatModel m_endPointModel;
 	BoolModel m_reverseModel;
 	BoolModel m_loopModel;
+	BoolModel m_stutterModel;
+
+	f_cnt_t m_nextPlayStartPoint;
 
 	friend class AudioFileProcessorView;
 
@@ -131,6 +135,7 @@
 	pixmapButton * m_openAudioFileButton;
 	pixmapButton * m_reverseButton;
 	pixmapButton * m_loopButton;
+	pixmapButton * m_stutterButton;
 
 } ;