devalang 0.2.0

Write music with code. Devalang is a domain-specific language (DSL) for sound designers and music hackers. Compose, automate, and control sound โ€” in plain text.
Documentation
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# Contributing to Devalang


First off, thank you for considering contributing to Devalang! ๐ŸŽ‰

It's people like you that make Devalang such a great tool. We welcome contributions from everyone, whether it's:

- ๐Ÿ› Bug reports
- ๐Ÿ’ก Feature requests
- ๐Ÿ“ Documentation improvements
- ๐ŸŽต Example contributions
- ๐Ÿ”ง Code contributions
- ๐ŸŒ Translations

---

## ๐Ÿ“‹ Table of Contents


- [Code of Conduct]#code-of-conduct
- [Getting Started]#getting-started
- [Development Workflow]#development-workflow
- [Submitting Changes]#submitting-changes
- [Coding Guidelines]#coding-guidelines
- [Testing]#testing
- [Documentation]#documentation
- [Community]#community

---

## ๐Ÿ“œ Code of Conduct


This project and everyone participating in it is governed by our Code of Conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to contact@devaloop.com.

### Our Standards


- โœ… Be respectful and inclusive
- โœ… Welcome newcomers and help them learn
- โœ… Focus on what is best for the community
- โœ… Show empathy towards other community members

---

## ๐Ÿš€ Getting Started


### Prerequisites


- **Rust** 1.70+ with Cargo
- **Node.js** 16+ with npm
- **Git** for version control
- **Code editor** (VS Code recommended)

### Fork and Clone


1. Fork the repository on GitHub
2. Clone your fork locally:

```bash
git clone https://github.com/YOUR_USERNAME/devalang.git
cd devalang
```

3. Add upstream remote:

```bash
git remote add upstream https://github.com/devaloop-labs/devalang.git
```

### Install Dependencies


```bash
# Install Rust dependencies

cargo build

# Install Node.js dependencies

npm install

# Build TypeScript

npm run ts:build
```

### Verify Setup


```bash
# Run tests

cargo test --features cli
npm test

# Check code formatting

cargo fmt --check
```

---

## ๐Ÿ› ๏ธ Development Workflow


### 1. Create a Branch


```bash
git checkout -b feature/your-feature-name
# or

git checkout -b fix/your-bug-fix
```

Branch naming conventions:
- `feature/` for new features
- `fix/` for bug fixes
- `docs/` for documentation
- `test/` for test additions
- `refactor/` for code refactoring

### 2. Make Changes


#### Rust Development


```bash
# Build the project

cargo build --features cli

# Run with your changes

cargo run --features cli -- build --path examples/simple.deva

# Format code

cargo fmt

# Run clippy for linting

cargo clippy --features cli -- -D warnings
```

#### TypeScript Development


```bash
# Build TypeScript

npm run ts:build

# Watch mode

npm run ts:watch

# Test your changes

npm test
```

### 3. Test Your Changes


```bash
# Run all Rust tests

cargo test --features cli,wasm

# Run TypeScript tests

npm test

# Test on specific examples

cargo run --features cli -- check --entry examples/
```

### 4. Commit Your Changes


We use [Conventional Commits](https://www.conventionalcommits.org/):

```bash
git add .
git commit -m "feat: add new synth oscillator type"
# or

git commit -m "fix: resolve pattern parsing issue"
# or

git commit -m "docs: improve README examples"
```

Commit types:
- `feat:` new feature
- `fix:` bug fix
- `docs:` documentation only
- `style:` formatting, missing semicolons, etc.
- `refactor:` code refactoring
- `test:` adding tests
- `chore:` maintenance

---

## ๐Ÿ“ค Submitting Changes


### Pull Request Process


1. **Update your fork**:
```bash
git fetch upstream

git rebase upstream/main

```

2. **Push to your fork**:
```bash
git push origin feature/your-feature-name

```

3. **Create Pull Request**:
   - Go to GitHub and create a PR from your branch
   - Fill out the PR template completely
   - Link any related issues

### PR Title Format


```
<type>: <short description>
```

Examples:
- `feat: add MP3 export support`
- `fix: resolve WASM bank injection error`
- `docs: add synth examples to README`

### PR Description


Include:
- **What**: Describe the changes
- **Why**: Explain the motivation
- **How**: Outline the approach
- **Testing**: Describe how you tested
- **Screenshots**: If UI changes (optional)

### Review Process


- Maintainers will review your PR
- Address feedback and requested changes
- Once approved, your PR will be merged
- Your contribution will be credited in the changelog

---

## ๐Ÿ’ป Coding Guidelines


### Rust Style


- Follow the [Rust API Guidelines]https://rust-lang.github.io/api-guidelines/
- Use `cargo fmt` for formatting
- Use `cargo clippy` for linting
- Add documentation comments (`///`) for public APIs
- Keep functions focused and small
- Use descriptive variable names

Example:
```rust
/// Renders audio from DevaLang code
/// 
/// # Arguments
/// * `code` - The DevaLang source code
/// * `options` - Rendering options (sample rate, BPM)
/// 
/// # Returns
/// * `Result<Vec<f32>>` - Audio buffer or error
pub fn render_audio(code: &str, options: RenderOptions) -> Result<Vec<f32>> {
    // Implementation
}
```

### TypeScript Style


- Use TypeScript strict mode
- Follow ESLint rules
- Use meaningful variable names
- Add JSDoc comments for exported functions
- Prefer `const` over `let`
- Use async/await over callbacks

Example:
```typescript
/**
 * Parse DevaLang code to AST
 * @param code - DevaLang source code
 * @returns Parsed AST or error
 */
export async function parse(code: string): Promise<AST> {
  // Implementation
}
```

### Devalang Code Style

- Use 4 spaces for indentation
- Add comments for complex logic
- Group related statements
- Use descriptive variable names

Example:
```deva
# Set tempo
bpm 120

# Load bank
bank devaloop.808 as drums

# Create pattern
pattern kick with drums.kick = "x--- x--- x--- x---"
```

---

## ๐Ÿงช Testing


### Writing Tests


#### Rust Unit Tests


```rust
#[cfg(test)]

mod tests {
    use super::*;

    #[test]
    fn test_tempo_validation() {
        let result = execute_tempo(120.0);
        assert!(result.is_ok());
    }
}
```

#### TypeScript Tests


```typescript
describe('render', () => {
  it('should render audio from code', async () => {
    const code = 'bpm 120';
    const result = await render(code);
    expect(result).toBeDefined();
  });
});
```

### Running Tests


```bash
# Run all tests

cargo test --features cli,wasm
npm test

# Run specific test

cargo test test_tempo_validation
npm test -- --grep "render"

# Run with coverage (if configured)

cargo tarpaulin
npm run test:coverage
```

---

## ๐Ÿ“š Documentation


### Where to Document


- **Code comments**: For implementation details
- **Doc comments**: For public APIs
- **README.md**: For getting started
- **CHANGELOG.md**: For version changes
- **Examples**: For usage demonstrations

### Documentation Style


- Be clear and concise
- Include examples
- Explain the "why" not just the "what"
- Keep it up to date

### Adding Examples


1. Create a `.deva` file in `examples/`
2. Add comments explaining the code
3. Test it works: `devalang check --entry examples/your-example.deva`
4. Document it in README if significant

---

## ๐ŸŽฏ Issue Guidelines


### Reporting Bugs


Use the bug report template and include:
- **Environment**: OS, Rust version, Node version
- **Steps to reproduce**: Minimal example
- **Expected behavior**: What should happen
- **Actual behavior**: What actually happens
- **Error messages**: Copy-paste full errors
- **Code sample**: Minimal DevaLang code that triggers the bug

### Feature Requests


Use the feature request template and include:
- **Problem**: What problem does this solve?
- **Solution**: Describe your proposed solution
- **Alternatives**: What alternatives have you considered?
- **Examples**: Show example usage

---

## ๐Ÿ’ฌ Community


### Communication Channels


- **GitHub Issues**: For bugs and feature requests
- **GitHub Discussions**: For questions and ideas
- **Discord**: For real-time chat (coming soon)
- **Email**: contact@devaloop.com for private inquiries

### Getting Help


- Check the [documentation]https://docs.devalang.com
- Search existing issues
- Ask in GitHub Discussions
- Join our Discord community

---

## ๐Ÿ† Recognition


Contributors are recognized in:
- CHANGELOG.md for each release
- GitHub contributors page
- Project README (for significant contributions)

---

## ๐Ÿ“œ License


By contributing, you agree that your contributions will be licensed under the MIT License.

---

## โ“ Questions?


Don't hesitate to ask! We're here to help:
- Open a [GitHub Discussion]https://github.com/devaloop-labs/devalang/discussions
- Email us at contact@devaloop.com
- Check our [FAQ]https://docs.devalang.com/faq

---

<div align="center">
    <strong>Thank you for contributing to Devalang! ๐ŸฆŠ</strong>
    <br />
    <sub>Every contribution makes a difference</sub>
</div>