This is related to BPM

Popular New Releases in BPM

airflow

Apache Airflow 2.2.5

argo-workflows

v3.3.2

prefect

Release 1.2.0

Activiti

incubator-dolphinscheduler

1.3.5 Release Notes

Popular Libraries in BPM

airflow

by apache doticonpythondoticon

star image 25547 doticonApache-2.0

Apache Airflow - A platform to programmatically author, schedule, and monitor workflows

n8n

by n8n-io doticontypescriptdoticon

star image 22046 doticonNOASSERTION

Free and open fair-code licensed node based Workflow Automation Tool. Easily automate tasks across different services.

kuboard-press

by eip-work doticonjavascriptdoticon

star image 11211 doticon

Kuboard 是基于 Kubernetes 的微服务管理界面。同时提供 Kubernetes 免费中文教程,入门教程,最新版本的 Kubernetes v1.20 安装手册,(k8s install) 在线答疑,持续更新。

argo-workflows

by argoproj doticongodoticon

star image 10889 doticonApache-2.0

Workflow engine for Kubernetes

platform_frameworks_base

by aosp-mirror doticonjavadoticon

star image 9696 doticonNOASSERTION

prefect

by PrefectHQ doticonpythondoticon

star image 8737 doticonApache-2.0

The easiest way to automate your data

Activiti

by Activiti doticonjavadoticon

star image 8513 doticonApache-2.0

Activiti is a light-weight workflow and Business Process Management (BPM) Platform targeted at business people, developers and system admins. Its core is a super-fast and rock-solid BPMN 2 process engine for Java. It's open-source and distributed under the Apache license. Activiti runs in any Java application, on a server, on a cluster or in the cloud. It integrates perfectly with Spring, it is extremely lightweight and based on simple concepts.

bpmn-js

by bpmn-io doticonjavascriptdoticon

star image 6017 doticonNOASSERTION

A BPMN 2.0 rendering toolkit and web modeler.

starter-workflows

by actions doticontypescriptdoticon

star image 5900 doticonNOASSERTION

Accelerating new GitHub Actions workflows

Trending New libraries in BPM

orchest

by orchest doticonpythondoticon

star image 2877 doticonAGPL-3.0

Build data pipelines, the easy way 🛠️

pipedream

by PipedreamHQ doticonjavascriptdoticon

star image 2869 doticonMIT

Connect APIs, remarkably fast. Free for developers.

actionsflow

by actionsflow doticontypescriptdoticon

star image 2338 doticonMIT

The free Zapier/IFTTT alternative for developers to automate your workflows based on Github actions

ploomber

by ploomber doticonpythondoticon

star image 2301 doticonApache-2.0

The fastest ⚡️ way to build data pipelines. Develop iteratively, deploy anywhere. ☁️

fastmac

by fastai doticonshelldoticon

star image 2006 doticonApache-2.0

Get a MacOS or Linux shell, for free, in around 2 minutes

git-branchless

by arxanas doticonrustdoticon

star image 1661 doticonGPL-2.0

High-velocity, monorepo-scale workflow for Git

tasuku

by privatenumber doticontypescriptdoticon

star image 1481 doticonMIT

✅ タスク — The minimal task runner for Node.js

compileflow

by alibaba doticonjavadoticon

star image 869 doticonApache-2.0

🎨 core business process engine of Alibaba Halo platform, best process engine for trade scenes. | 一个高性能流程编排引擎

actionlint

by rhysd doticongodoticon

star image 721 doticonMIT

:octocat: Static checker for GitHub Actions workflow files

Top Authors in BPM

1

camunda

45 Libraries

star icon6269

2

deanishe

38 Libraries

star icon7042

3

bpmn-io

33 Libraries

star icon8661

4

camunda-community-hub

24 Libraries

star icon571

5

PacktPublishing

21 Libraries

star icon242

6

jenkinsci

14 Libraries

star icon1074

7

holunda-io

13 Libraries

star icon154

8

common-workflow-language

12 Libraries

star icon1681

9

StephenOTT

12 Libraries

star icon125

10

temporalio

11 Libraries

star icon4816

1

45 Libraries

star icon6269

2

38 Libraries

star icon7042

3

33 Libraries

star icon8661

4

24 Libraries

star icon571

5

21 Libraries

star icon242

6

14 Libraries

star icon1074

7

13 Libraries

star icon154

8

12 Libraries

star icon1681

9

12 Libraries

star icon125

10

11 Libraries

star icon4816

Trending Kits in BPM

Java BPM libraries will enable developers to efficiently manage and automate complex business processes. With Java BPM libraries, developers can integrate with other systems and services, automate decision-making, and monitor real-time process performance. By discovering, establishing, enforcing, covering, and optimizing business processes, businesses can reduce costs, boost client satisfaction, and drive invention. 


The Java BPM libraries are a foundation for automating the description, perpetration, and control of business processes. By leveraging the power of Java BPM libraries, businesses can optimize their processes and achieve better results. These libraries give a variety of functions, including system and data source integration, process modeling, prosecution, monitoring, and optimization. By utilizing these libraries, businesses can boost effectiveness, streamline processes, and gain less knowledge of their day-to-day operations. 



Here is a list of the 8 Best Java BPM Libraries: 


Activiti 

  • Helps in implementing custom workflows for approval, review, and other business processes. 
  • Useful for integrating with other systems through REST and Java APIs. 
  • Helps in managing complex event-driven workflows. 
  • Useful for automating human-centric workflows with support for user tasks and forms. 

Flowable-engine

  • Helps in creating and managing workflows with BPMN 2.0 standard notation. 
  • Useful for building microservices-based workflows with support for REST and message-based integration. 
  • Helps in automating decision-making with DMN (Decision Model and Notation) tables. 
  • Useful for creating process dashboards and analytics reports for monitoring and optimization.

Camunda-bpm-platform

  • Helps in creating and managing workflows with BPMN 2.0 standard notation. 
  • Useful for building event-driven workflows with support for messaging and external triggers. 
  • Helps in automating decision-making with DMN (Decision Model and Notation) tables. 
  • Useful for creating process metrics and analytics dashboards for performance monitoring. 

jBPM 

  • Helps in defining and executing business processes with BPMN 2.0 standard notation. 
  • Useful for integrating with various data sources and middleware technologies. 
  • Helps in monitoring and reporting on process performance in real-time. 
  • Useful for creating decision tables and rules to automate decision-making in business. processes 

Kogito-runtimes

  • Helps in creating and executing cloud-native workflows with Kubernetes and OpenShift support. 
  • Useful for building event-driven workflows with support for messaging and external triggers. 
  • Helps in automating decision-making with DMN (Decision Model and Notation) tables. 
  • Useful for creating process dashboards and analytics reports for monitoring and optimization. 

Imixs-Workflow 

  • Helps in designing and implementing human-centric workflows with support for user tasks and forms. 
  • Useful for integrating with various data sources and middleware technologies. 
  • Helps in managing complex workflows with sub-processes and parallel flows. 
  • Useful for creating custom plugins and extensions for extending its functionality.

Bonita-engine

  • Helps in designing and executing business processes with a visual drag-and-drop interface. 
  • Useful for integrating with third-party systems and services through REST and Java APIs. 
  • Helps in managing complex workflows with sub-processes and parallel flows. 
  • Useful for creating custom connectors and plugins for extending its functionality. 

ODE 

  • Helps in implementing and managing complex workflows with BPEL (Business Process Execution Language) standard notation. 
  • Useful for integrating with various data sources and middleware technologies. 
  • Helps in monitoring and reporting on process performance in real-time. 
  • Useful for creating custom extensions and plugins for extending its functionality. 

Trending Discussions on BPM

Camunda embedded with H2: Cockpit Login fails

Plot line from dataframe

Camunda Application not starting up on docker container

Renaming some part of columns of dataframe with values from another dataframe

How to separate Camunda tables to a different schema?

How to convert json MySQL data into rows and column

Using pyaudio to build a Metronome; wrong timing

Why am I getting "Error processing transaction request: intrinsic gas too low" error when trying to add tUSDT to a particular account?

getting a KeyNotFoundException on a key that appears to exist in a dictionary

Webaudio timing performance

QUESTION

Camunda embedded with H2: Cockpit Login fails

Asked 2022-Mar-09 at 08:50

I'm currently wokring on a product with the following conditions:

  • Spring-Boot (2.6) with Camunda embedded (7.16)
  • Connection to Camunda configured to use H2 (2.1.210) embedded with the following is configured in application.yml:
1app:
2  datasource-camunda:
3    jdbcUrl: jdbc:h2:./h2/test;MODE=LEGACY
4camunda:
5  bpm:
6    database:
7      schema-update: true
8    auto-deployment-enabled: true
9

and as Java-Configuration:

1app:
2  datasource-camunda:
3    jdbcUrl: jdbc:h2:./h2/test;MODE=LEGACY
4camunda:
5  bpm:
6    database:
7      schema-update: true
8    auto-deployment-enabled: true
9@Bean("camundaBpmDataSource")
10@ConfigurationProperties
11public DataSource camundaDataSource() {
12  return DataSourceBuilder.create().build();
13}
14
15@Bean
16public PlatformTransactionManager camundaBpmTransactionManager(DataSource datasource) {
17  return new DataSourceTransactionManager(datasource)
18}
19

The camunda engine is not configured explicitly since I used the appropriate starter and let Spring auto configured it. As a result the resulting setup should look very similar to the embedded camunda h2 configuration showed here: https://docs.camunda.org/get-started/spring/embedded-process-engine/

The application runs good with this setup. No problems with the application at all, but I faced an issue while logging in to the camunda cockpit. Login succeeds but then I see an error in the login mask saying:

Login Failed

An exception occured in the persistence layer. Please check the server logs for a detailed message and the entire exception stack trace

1app:
2  datasource-camunda:
3    jdbcUrl: jdbc:h2:./h2/test;MODE=LEGACY
4camunda:
5  bpm:
6    database:
7      schema-update: true
8    auto-deployment-enabled: true
9@Bean("camundaBpmDataSource")
10@ConfigurationProperties
11public DataSource camundaDataSource() {
12  return DataSourceBuilder.create().build();
13}
14
15@Bean
16public PlatformTransactionManager camundaBpmTransactionManager(DataSource datasource) {
17  return new DataSourceTransactionManager(datasource)
18}
19
20
21Caused by: org.h2.jdbc.JdbcSQLNonTransientException: Unbekannter Datentyp: "?2"
22
23Unknown data type: "?2"; SQL statement:
24
25SELECT
26
27    CASE
28
29 
30
31     
32
33       
34
35        WHEN
36
37          
38
39           
40
41          EXISTS
42
43          
44
45            (SELECT
46
47                    A.RESOURCE_ID_
48
49             FROM
50
51                    ACT_RU_AUTHORIZATION A
52
53             WHERE
54
55                    A.TYPE_ = 1
56
57             AND
58
59                    A.USER_ID_ = ?
60
61             AND
62
63                    BITAND(A.PERMS_,?) = ?
64
65             AND
66
67                    A.RESOURCE_TYPE_ = ?
68
69             AND
70
71                    A.RESOURCE_ID_ =  ? )
72
73        THEN 1
74
75      
76
77 
78
79     
80
81       
82
83 
84
85     
86
87      WHEN
88
89        EXISTS
90
91          (SELECT
92
93                  ID_
94
95           FROM
96
97                  ACT_RU_AUTHORIZATION A
98
99           WHERE
100
101                  A.TYPE_ = 1
102
103           AND
104
105                  A.USER_ID_ = ?
106
107           AND
108
109                  BITAND(A.PERMS_,?) = ?
110
111           AND
112
113                  A.RESOURCE_TYPE_ = ?
114
115           AND
116
117                  A.RESOURCE_ID_ = '*')
118
119        THEN 1
120
121 
122
123     
124
125       
126
127 
128
129      ELSE
130
131          (
132
133          SELECT
134
135            CASE
136
137              
138
139 
140
141               
142
143                 
144
145                  WHEN
146
147                    
148
149                     
150
151                    EXISTS
152
153                    
154
155                      (SELECT
156
157                              A.RESOURCE_ID_
158
159                       FROM
160
161                              ACT_RU_AUTHORIZATION A
162
163                       WHERE
164
165                              A.TYPE_ = 1
166
167                       AND
168
169                              A.GROUP_ID_ IN  (  ? )
170
171                       AND
172
173                              BITAND(A.PERMS_,?) = ?
174
175                       AND
176
177                              A.RESOURCE_TYPE_ = ?
178
179                       AND
180
181                              A.RESOURCE_ID_ =  ? )
182
183                  THEN 1
184
185                
186
187 
188
189               
190
191                 
192
193 
194
195               
196
197                WHEN
198
199                  EXISTS
200
201                    (SELECT
202
203                            ID_
204
205                     FROM
206
207                            ACT_RU_AUTHORIZATION A
208
209                     WHERE
210
211                            A.TYPE_ = 1
212
213                     AND
214
215                            A.GROUP_ID_ IN  (  ? )
216
217                     AND
218
219                            BITAND(A.PERMS_,?) = ?
220
221                     AND
222
223                            A.RESOURCE_TYPE_ = ?
224
225                     AND
226
227                            A.RESOURCE_ID_ = '*')
228
229                  THEN 1
230
231 
232
233               
234
235                 
236
237 
238
239                ELSE (
240
241                      SELECT
242
243                        CASE
244
245              
246
247                          
248
249                           
250
251                            WHEN
252
253                              
254
255                               
256
257                              EXISTS
258
259                              
260
261                                (SELECT
262
263                                        A.RESOURCE_ID_
264
265                                 FROM
266
267                                        ACT_RU_AUTHORIZATION A
268
269                                 WHERE
270
271                                        A.TYPE_ = 0
272
273                                 AND
274
275                                        A.USER_ID_ = '*'
276
277                                 AND
278
279                                        BITAND(A.PERMS_,?) = ?
280
281                                 AND
282
283                                        A.RESOURCE_TYPE_ = ?
284
285                                 AND
286
287                                        A.RESOURCE_ID_ =  ? )
288
289                            THEN 1
290
291                          
292
293 
294
295                         
296
297                           
298
299 
300
301                         
302
303                          WHEN
304
305                            EXISTS
306
307                              (SELECT
308
309                                      ID_
310
311                               FROM
312
313                                      ACT_RU_AUTHORIZATION A
314
315                               WHERE
316
317                                      A.TYPE_ = 0
318
319                               AND
320
321                                      A.USER_ID_ = '*'
322
323                               AND
324
325                                      BITAND(A.PERMS_,?) = ?
326
327                               AND
328
329                                      A.RESOURCE_TYPE_ = ?
330
331                               AND
332
333                                      A.RESOURCE_ID_ = '*')
334
335                            THEN 1
336
337 
338
339                          
340
341                           
342
343 
344
345                         
346
347                          ELSE
348
349                          
350
351                           
352
353                            null
354
355                          
356
357 
358
359              
360
361                        END
362
363                )
364
365              
366
367            END
368
369      )
370
371    END [50004-210]
372
373            at org.h2.message.DbException.getJdbcSQLException(DbException.java:573) ~[h2-2.1.210.jar:2.1.210]
374
375            at org.h2.message.DbException.getJdbcSQLException(DbException.java:496) ~[h2-2.1.210.jar:2.1.210]
376
377            at org.h2.message.DbException.get(DbException.java:227) ~[h2-2.1.210.jar:2.1.210]
378

I already took a look into the database and saw all tables where created sucesfully, so does anybody faced a similar issue?

ANSWER

Answered 2022-Mar-09 at 08:50

Remove the "MODE=LEGACY" from the url. Here is a working example:

https://github.com/rob2universe/vanilla-camunda-template/blob/4625376bf3a5eed9cd1f2853cdf07fe5eca46685/src/main/resources/application.yaml#L17

Also ensure you use a supported H2 version. That is 1.4.x fro 7.16.x: https://docs.camunda.org/manual/7.16/introduction/supported-environments/

The BOM will inclcude H2 1.4.200.

Source https://stackoverflow.com/questions/71391717

QUESTION

Plot line from dataframe

Asked 2022-Mar-04 at 17:04

I have the following dataframe [1] which contains information relating to music listening. I would like to print a line graph like the following 2 (I got it by putting the data manually) in which the slotID and the average bpm are related, without writing the values by hand . Each segment must be one unit long and must match the average bpm.

[1]

1        slotID  NUn  NTot     MeanBPM
22        2       3       13  107.987769
39       11       3       30  133.772100
410      12       3       40  122.354025
513      15       4       44  123.221659
614      16       4       30  129.083900
715      17       9       66  123.274409
816      18       4       25  131.323480
918      20       5       40  124.782625
1019      21       6       30  127.664467
1120      22       6       19  120.483579
12

enter image description here

The code I used to obtain the plot is the following:

1        slotID  NUn  NTot     MeanBPM
22        2       3       13  107.987769
39       11       3       30  133.772100
410      12       3       40  122.354025
513      15       4       44  123.221659
614      16       4       30  129.083900
715      17       9       66  123.274409
816      18       4       25  131.323480
918      20       5       40  124.782625
1019      21       6       30  127.664467
1120      22       6       19  120.483579
12import numpy as np
13import pylab as pl
14from matplotlib import collections  as mc
15
16lines = [ [(2, 107), (3,107)], [(11,133),(12,133)], [(12,122),(13,122)], ]
17c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)])
18
19lc = mc.LineCollection(lines, colors=c, linewidths=2)
20fig, ax = pl.subplots()
21ax.add_collection(lc)
22ax.autoscale()
23ax.margins(0.1)
24

To obtain data:

1        slotID  NUn  NTot     MeanBPM
22        2       3       13  107.987769
39       11       3       30  133.772100
410      12       3       40  122.354025
513      15       4       44  123.221659
614      16       4       30  129.083900
715      17       9       66  123.274409
816      18       4       25  131.323480
918      20       5       40  124.782625
1019      21       6       30  127.664467
1120      22       6       19  120.483579
12import numpy as np
13import pylab as pl
14from matplotlib import collections  as mc
15
16lines = [ [(2, 107), (3,107)], [(11,133),(12,133)], [(12,122),(13,122)], ]
17c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)])
18
19lc = mc.LineCollection(lines, colors=c, linewidths=2)
20fig, ax = pl.subplots()
21ax.add_collection(lc)
22ax.autoscale()
23ax.margins(0.1)
24import numpy as np
25import pandas as pd
26
27
28
29dfLunedi = pd.read_csv( "5.sab.csv", encoding = "ISO-8859-1", sep = ';')
30
31dfSlotMean = dfLunedi.groupby('slotID', as_index=False).agg( NSabUn=('date', 'nunique'),NSabTot = ('date', 'count'), MeanBPM=('tempo', 'mean') )
32
33
34
35df = pd.DataFrame(dfSlotMean)
36df.to_csv('sil.csv', sep = ';', index=False)
37
38df.drop(df[df.NSabUn < 3].index, inplace=True)
39

ANSWER

Answered 2022-Mar-04 at 17:04

You can loop through the rows and plot each segment like this:

1        slotID  NUn  NTot     MeanBPM
22        2       3       13  107.987769
39       11       3       30  133.772100
410      12       3       40  122.354025
513      15       4       44  123.221659
614      16       4       30  129.083900
715      17       9       66  123.274409
816      18       4       25  131.323480
918      20       5       40  124.782625
1019      21       6       30  127.664467
1120      22       6       19  120.483579
12import numpy as np
13import pylab as pl
14from matplotlib import collections  as mc
15
16lines = [ [(2, 107), (3,107)], [(11,133),(12,133)], [(12,122),(13,122)], ]
17c = np.array([(1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1)])
18
19lc = mc.LineCollection(lines, colors=c, linewidths=2)
20fig, ax = pl.subplots()
21ax.add_collection(lc)
22ax.autoscale()
23ax.margins(0.1)
24import numpy as np
25import pandas as pd
26
27
28
29dfLunedi = pd.read_csv( "5.sab.csv", encoding = "ISO-8859-1", sep = ';')
30
31dfSlotMean = dfLunedi.groupby('slotID', as_index=False).agg( NSabUn=('date', 'nunique'),NSabTot = ('date', 'count'), MeanBPM=('tempo', 'mean') )
32
33
34
35df = pd.DataFrame(dfSlotMean)
36df.to_csv('sil.csv', sep = ';', index=False)
37
38df.drop(df[df.NSabUn < 3].index, inplace=True)
39for _, r in df.iterrows():
40    plt.plot([r['slotID'], r['slotID']+1], [r['MeanBPM']]*2)
41

Output:

enter image description here

Source https://stackoverflow.com/questions/71354696

QUESTION

Camunda Application not starting up on docker container

Asked 2022-Feb-27 at 06:01

I have a simple cammunda spring boot application. which I want to run in a docker container

I am able to run it locally from IntelliJ but when I try to run it inside a docker it fails with below error message:

08043 Exception while performing 'Deployment of Process Application camundaApplication' => 'Deployment of process archive 'ct-camunda': The deployment contains definitions with the same key 'ct-camunda' (id attribute), this is not allowed

docker-compose.yml

1version: '2'
2
3services:
4  myaap:
5    build: .
6    ports:
7      - "8080:8080"
8

processes.yml

1version: '2'
2
3services:
4  myaap:
5    build: .
6    ports:
7      - "8080:8080"
8<process-application xmlns="http://www.camunda.org/schema/1.0/ProcessApplication">
9
10    <process-engine name="my-engine">
11        <configuration>org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration</configuration>
12    </process-engine>
13
14    <process-archive name="ct-camunda" tenantId="ct-camunda">
15        <process-engine>default</process-engine>
16        <resource>ct-camunda.bpmn</resource>
17        <properties>
18            <property name="isDeleteUponUndeploy">false</property>
19            <property name="isScanForProcessDefinitions">true</property>
20        </properties>
21    </process-archive>
22
23</process-application>
24

Dockerfile

1version: '2'
2
3services:
4  myaap:
5    build: .
6    ports:
7      - "8080:8080"
8<process-application xmlns="http://www.camunda.org/schema/1.0/ProcessApplication">
9
10    <process-engine name="my-engine">
11        <configuration>org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration</configuration>
12    </process-engine>
13
14    <process-archive name="ct-camunda" tenantId="ct-camunda">
15        <process-engine>default</process-engine>
16        <resource>ct-camunda.bpmn</resource>
17        <properties>
18            <property name="isDeleteUponUndeploy">false</property>
19            <property name="isScanForProcessDefinitions">true</property>
20        </properties>
21    </process-archive>
22
23</process-application>
24FROM openjdk:11
25ARG JAR_FILE=target/camunda-0.0.1-SNAPSHOT-exec.jar
26COPY ${JAR_FILE} app.jar
27ENTRYPOINT ["java","-jar","/app.jar"]
28

Main class CamundaApplication.java

1version: '2'
2
3services:
4  myaap:
5    build: .
6    ports:
7      - "8080:8080"
8<process-application xmlns="http://www.camunda.org/schema/1.0/ProcessApplication">
9
10    <process-engine name="my-engine">
11        <configuration>org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration</configuration>
12    </process-engine>
13
14    <process-archive name="ct-camunda" tenantId="ct-camunda">
15        <process-engine>default</process-engine>
16        <resource>ct-camunda.bpmn</resource>
17        <properties>
18            <property name="isDeleteUponUndeploy">false</property>
19            <property name="isScanForProcessDefinitions">true</property>
20        </properties>
21    </process-archive>
22
23</process-application>
24FROM openjdk:11
25ARG JAR_FILE=target/camunda-0.0.1-SNAPSHOT-exec.jar
26COPY ${JAR_FILE} app.jar
27ENTRYPOINT ["java","-jar","/app.jar"]
28@SpringBootApplication
29@EnableProcessApplication
30public class CamundaApplication {
31
32    public static void main(String[] args) {
33        SpringApplication.run(CamundaApplication.class, args);
34    }
35}
36

Error logs:

1version: '2'
2
3services:
4  myaap:
5    build: .
6    ports:
7      - "8080:8080"
8<process-application xmlns="http://www.camunda.org/schema/1.0/ProcessApplication">
9
10    <process-engine name="my-engine">
11        <configuration>org.camunda.bpm.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration</configuration>
12    </process-engine>
13
14    <process-archive name="ct-camunda" tenantId="ct-camunda">
15        <process-engine>default</process-engine>
16        <resource>ct-camunda.bpmn</resource>
17        <properties>
18            <property name="isDeleteUponUndeploy">false</property>
19            <property name="isScanForProcessDefinitions">true</property>
20        </properties>
21    </process-archive>
22
23</process-application>
24FROM openjdk:11
25ARG JAR_FILE=target/camunda-0.0.1-SNAPSHOT-exec.jar
26COPY ${JAR_FILE} app.jar
27ENTRYPOINT ["java","-jar","/app.jar"]
28@SpringBootApplication
29@EnableProcessApplication
30public class CamundaApplication {
31
32    public static void main(String[] args) {
33        SpringApplication.run(CamundaApplication.class, args);
34    }
35}
362022-02-25 03:21:24.724  INFO 1 --- [           main] org.camunda.bpm.container                : ENGINE-08023 Deployment summary for process archive 'ct-camunda': 
37
38
39        ct-camunda.bpmn
40
41        BOOT-INF/classes/ct-camunda.bpmn
42
43
442022-02-25 03:21:25.067 ERROR 1 --- [           main] org.camunda.bpm.engine.context           : ENGINE-16004 Exception while closing command context: The deployment contains definitions with the same key 'ct-camunda' (id attribute), this is not allowed
45
46
47org.camunda.bpm.engine.ProcessEngineException: The deployment contains definitions with the same key 'ct-camunda' (id attribute), this is not allowed
48
49at org.camunda.bpm.engine.impl.AbstractDefinitionDeployer.ensureNoDuplicateDefinitionKeys(AbstractDefinitionDeployer.java:192) ~[camunda-engine-7.16.0.jar!/:7.16.0]
50
51at org.camunda.bpm.engine.impl.AbstractDefinitionDeployer.deploy(AbstractDefinitionDeployer.java:65) ~[camunda-engine-7.16.0.jar!/:7.16.0]
52
53at org.camunda.bpm.engine.impl.persistence.deploy.cache.CacheDeployer$1.call(CacheDeployer.java:54) ~[camunda-engine-7.16.0.jar!/:7.16.0]
54
55at org.camunda.bpm.engine.impl.persistence.deploy.cache.CacheDeployer$1.call(CacheDeployer.java:51) ~[camunda-engine-7.16.0.jar!/:7.16.0]
56
57at org.camunda.bpm.engine.impl.interceptor.CommandContext.runWithoutAuthorization(CommandContext.java:559) ~[camunda-engine-7.16.0.jar!/:7.16.0]
58
59at org.camunda.bpm.engine.impl.interceptor.CommandContext.runWithoutAuthorization(CommandContext.java:547) ~[camunda-engine-7.16.0.jar!/:7.16.0]
60
61at org.camunda.bpm.engine.impl.persistence.deploy.cache.CacheDeployer.deploy(CacheDeployer.java:51) ~[camunda-engine-7.16.0.jar!/:7.16.0]
62
63at org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache.deploy(DeploymentCache.java:71) ~[camunda-engine-7.16.0.jar!/:7.16.0]
64
65at org.camunda.bpm.engine.impl.persistence.entity.DeploymentManager.insertDeployment(DeploymentManager.java:64) ~[camunda-engine-7.16.0.jar!/:7.16.0]
66
67at org.camunda.bpm.engine.impl.cmd.DeployCmd.deploy(DeployCmd.java:254) ~[camunda-engine-7.16.0.jar!/:7.16.0]
68
69at org.camunda.bpm.engine.impl.cmd.DeployCmd.lambda$doExecute$0(DeployCmd.java:155) ~[camunda-engine-7.16.0.jar!/:7.16.0]
70
71at org.camunda.bpm.engine.impl.interceptor.CommandContext.runWithoutAuthorization(CommandContext.java:559) ~[camunda-engine-7.16.0.jar!/:7.16.0]
72
73at org.camunda.bpm.engine.impl.interceptor.CommandContext.runWithoutAuthorization(CommandContext.java:547) ~[camunda-engine-7.16.0.jar!/:7.16.0]
74
75at org.camunda.bpm.engine.impl.cmd.DeployCmd.doExecute(DeployCmd.java:141) ~[camunda-engine-7.16.0.jar!/:7.16.0]
76
77at org.camunda.bpm.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:101) ~[camunda-engine-7.16.0.jar!/:7.16.0]
78
79at org.camunda.bpm.engine.impl.cmd.DeployCmd.execute(DeployCmd.java:81) ~[camunda-engine-7.16.0.jar!/:7.16.0]
80
81at org.camunda.bpm.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:28) ~[camunda-engine-7.16.0.jar!/:7.16.0]
82
83at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:110) ~[camunda-engine-7.16.0.jar!/:7.16.0]
84
85at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:72) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
86
87at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.3.9.jar!/:5.3.9]
88
89at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:70) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
90
91at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70) ~[camunda-engine-7.16.0.jar!/:7.16.0]
92
93at org.camunda.bpm.engine.impl.interceptor.CommandCounterInterceptor.execute(CommandCounterInterceptor.java:35) ~[camunda-engine-7.16.0.jar!/:7.16.0]
94
95at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33) ~[camunda-engine-7.16.0.jar!/:7.16.0]
96
97at org.camunda.bpm.engine.impl.RepositoryServiceImpl.deployWithResult(RepositoryServiceImpl.java:104) ~[camunda-engine-7.16.0.jar!/:7.16.0]
98
99at org.camunda.bpm.engine.impl.repository.DeploymentBuilderImpl.deployWithResult(DeploymentBuilderImpl.java:270) ~[camunda-engine-7.16.0.jar!/:7.16.0]
100
101at org.camunda.bpm.engine.impl.repository.DeploymentBuilderImpl.deploy(DeploymentBuilderImpl.java:266) ~[camunda-engine-7.16.0.jar!/:7.16.0]
102
103at org.camunda.bpm.engine.impl.repository.ProcessApplicationDeploymentBuilderImpl.deploy(ProcessApplicationDeploymentBuilderImpl.java:63) ~[camunda-engine-7.16.0.jar!/:7.16.0]
104
105at org.camunda.bpm.container.impl.deployment.DeployProcessArchiveStep.performOperationStep(DeployProcessArchiveStep.java:146) ~[camunda-engine-7.16.0.jar!/:7.16.0]
106
107at org.camunda.bpm.container.impl.spi.DeploymentOperation.execute(DeploymentOperation.java:120) ~[camunda-engine-7.16.0.jar!/:7.16.0]
108
109at org.camunda.bpm.container.impl.jmx.MBeanServiceContainer.executeDeploymentOperation(MBeanServiceContainer.java:160) ~[camunda-engine-7.16.0.jar!/:7.16.0]
110
111at org.camunda.bpm.container.impl.spi.DeploymentOperation$DeploymentOperationBuilder.execute(DeploymentOperation.java:216) ~[camunda-engine-7.16.0.jar!/:7.16.0]
112
113at org.camunda.bpm.container.impl.RuntimeContainerDelegateImpl.deployProcessApplication(RuntimeContainerDelegateImpl.java:102) ~[camunda-engine-7.16.0.jar!/:7.16.0]
114
115at org.camunda.bpm.application.AbstractProcessApplication.deploy(AbstractProcessApplication.java:71) ~[camunda-engine-7.16.0.jar!/:7.16.0]
116
117at org.camunda.bpm.engine.spring.application.SpringProcessApplication.start(SpringProcessApplication.java:110) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
118
119at org.camunda.bpm.engine.spring.application.SpringProcessApplication.afterPropertiesSet(SpringProcessApplication.java:119) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
120
121at org.camunda.bpm.spring.boot.starter.SpringBootProcessApplication.afterPropertiesSet(SpringBootProcessApplication.java:102) ~[camunda-bpm-spring-boot-starter-7.16.0.jar!/:7.16.0]
122
123at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:96) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
124
125at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:52) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
126
127at org.camunda.bpm.spring.boot.starter.SpringBootProcessApplication$$EnhancerBySpringCGLIB$$595e572.onApplicationEvent(<generated>) ~[camunda-bpm-spring-boot-starter-7.16.0.jar!/:7.16.0]
128
129at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.9.jar!/:5.3.9]
130
131at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.9.jar!/:5.3.9]
132
133at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.9.jar!/:5.3.9]
134
135at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.9.jar!/:5.3.9]
136
137at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.9.jar!/:5.3.9]
138
139at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938) ~[spring-context-5.3.9.jar!/:5.3.9]
140
141at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.9.jar!/:5.3.9]
142
143at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.4.jar!/:2.5.4]
144
145at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-2.5.4.jar!/:2.5.4]
146
147at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-2.5.4.jar!/:2.5.4]
148
149at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) ~[spring-boot-2.5.4.jar!/:2.5.4]
150
151at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) ~[spring-boot-2.5.4.jar!/:2.5.4]
152
153at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) ~[spring-boot-2.5.4.jar!/:2.5.4]
154
155at com.nk.ct.camunda.CamundaApplication.main(CamundaApplication.java:12) ~[classes!/:0.0.1-SNAPSHOT]
156
157at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
158
159at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
160
161at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
162
163at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
164
165at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[app.jar:0.0.1-SNAPSHOT]
166
167at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[app.jar:0.0.1-SNAPSHOT]
168
169at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[app.jar:0.0.1-SNAPSHOT]
170
171at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[app.jar:0.0.1-SNAPSHOT]
172
173
1742022-02-25 03:21:25.090  INFO 1 --- [           main] org.camunda.bpm.engine.jobexecutor       : ENGINE-14015 Shutting down the JobExecutor[org.camunda.bpm.engine.impl.jobexecutor.DefaultJobExecutor]
175
1762022-02-25 03:21:25.091  INFO 1 --- [ultJobExecutor]] org.camunda.bpm.engine.jobexecutor       : ENGINE-14020 JobExecutor[org.camunda.bpm.engine.impl.jobexecutor.DefaultJobExecutor] stopped job acquisition
177
1782022-02-25 03:21:25.111  INFO 1 --- [           main] org.camunda.bpm.engine.persistence       : ENGINE-03016 Performing database operation 'drop' on component 'decision.engine' with resource 'org/camunda/bpm/engine/db/drop/activiti.h2.drop.decision.engine.sql'
179
1802022-02-25 03:21:25.126  INFO 1 --- [           main] org.camunda.bpm.engine.persistence       : ENGINE-03016 Performing database operation 'drop' on component 'decision.history' with resource 'org/camunda/bpm/engine/db/drop/activiti.h2.drop.decision.history.sql'
181
1822022-02-25 03:21:25.138  INFO 1 --- [           main] org.camunda.bpm.engine.persistence       : ENGINE-03016 Performing database operation 'drop' on component 'case.engine' with resource 'org/camunda/bpm/engine/db/drop/activiti.h2.drop.case.engine.sql'
183
1842022-02-25 03:21:25.185  INFO 1 --- [           main] org.camunda.bpm.engine.persistence       : ENGINE-03016 Performing database operation 'drop' on component 'engine' with resource 'org/camunda/bpm/engine/db/drop/activiti.h2.drop.engine.sql'
185
1862022-02-25 03:21:25.191  INFO 1 --- [           main] org.camunda.bpm.engine.persistence       : ENGINE-03016 Performing database operation 'drop' on component 'case.history' with resource 'org/camunda/bpm/engine/db/drop/activiti.h2.drop.case.history.sql'
187
1882022-02-25 03:21:25.224  INFO 1 --- [           main] org.camunda.bpm.engine.persistence       : ENGINE-03016 Performing database operation 'drop' on component 'history' with resource 'org/camunda/bpm/engine/db/drop/activiti.h2.drop.history.sql'
189
1902022-02-25 03:21:25.233  INFO 1 --- [           main] org.camunda.bpm.engine.persistence       : ENGINE-03016 Performing database operation 'drop' on component 'identity' with resource 'org/camunda/bpm/engine/db/drop/activiti.h2.drop.identity.sql'
191
1922022-02-25 03:21:25.236  INFO 1 --- [           main] org.camunda.bpm.engine                   : ENGINE-00007 Process Engine my-engine closed
193
1942022-02-25 03:21:25.250  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
195
1962022-02-25 03:21:25.265  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 
197
198
199Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
200
2012022-02-25 03:21:25.303 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed
202
203
204java.lang.RuntimeException: org.camunda.bpm.engine.ProcessEngineException: ENGINE-08043 Exception while performing 'Deployment of Process Application camundaApplication' => 'Deployment of process archive 'ct-camunda': The deployment contains definitions with the same key 'ct-camunda' (id attribute), this is not allowed
205
206at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:105) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
207
208at org.camunda.bpm.engine.spring.application.SpringProcessApplication.onApplicationEvent(SpringProcessApplication.java:52) ~[camunda-engine-spring-7.16.0.jar!/:7.16.0]
209
210at org.camunda.bpm.spring.boot.starter.SpringBootProcessApplication$$EnhancerBySpringCGLIB$$595e572.onApplicationEvent(<generated>) ~[camunda-bpm-spring-boot-starter-7.16.0.jar!/:7.16.0]
211
212at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176) ~[spring-context-5.3.9.jar!/:5.3.9]
213
214at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169) ~[spring-context-5.3.9.jar!/:5.3.9]
215
216at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143) ~[spring-context-5.3.9.jar!/:5.3.9]
217
218at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:421) ~[spring-context-5.3.9.jar!/:5.3.9]
219
220at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:378) ~[spring-context-5.3.9.jar!/:5.3.9]
221
222at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:938) ~[spring-context-5.3.9.jar!/:5.3.9]
223
224at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586) ~[spring-context-5.3.9.jar!/:5.3.9]
225
226at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) ~[spring-boot-2.5.4.jar!/:2.5.4]
227

ANSWER

Answered 2022-Feb-25 at 11:07

I don't think this is Docker related. Maybe your build process copies files?

"The deployment contains definitions with the same key 'ct-camunda' (id attribute), this is not allowed" Check if you have packaged multiple .bpmn files into your deployment. Maybe you accidentally copied the model file in an additional classpath location. You seem to have two deployments with the same id. (This is not about the filename, but the technical id used inside the XML)

If you are using auto deployment in Spring Boot, you do not have to declare anything in the processes.xml. Use this only in combination with @EnableProcessApplication (or do not use both)

Source https://stackoverflow.com/questions/71260766

QUESTION

Renaming some part of columns of dataframe with values from another dataframe

Asked 2022-Feb-26 at 12:08

I want to change the column names from another DataFrame.

There are some similar questions in stackoverflow, but I need advanced version of it.

1data1 = {
2  "ABC-123_afd": [420, 380, 390],
3  "LFK-402_ote": [50, 40, 45],
4  "BPM-299_qbm": [50, 40, 45],
5}
6
7data2 = {
8  "ID": ['ABC-123', 'LFK-402', 'BPM-299'],
9  "NewID": ['IQU', 'EUW', 'NMS']
10}
11
12data1_df=pd.DataFrame(data1)
13#   ABC-123_afd  LFK-402_ote  BPM-299_qbm
14#0          420           50           50
15#1          380           40           40
16#2          390           45           45
17
18data2_df=pd.DataFrame(data2)
19#        ID NewID
20#0  ABC-123   IQU
21#1  LFK-402   EUW
22#2  BPM-299   NMS
23

I want to make the final result as below:

1data1 = {
2  "ABC-123_afd": [420, 380, 390],
3  "LFK-402_ote": [50, 40, 45],
4  "BPM-299_qbm": [50, 40, 45],
5}
6
7data2 = {
8  "ID": ['ABC-123', 'LFK-402', 'BPM-299'],
9  "NewID": ['IQU', 'EUW', 'NMS']
10}
11
12data1_df=pd.DataFrame(data1)
13#   ABC-123_afd  LFK-402_ote  BPM-299_qbm
14#0          420           50           50
15#1          380           40           40
16#2          390           45           45
17
18data2_df=pd.DataFrame(data2)
19#        ID NewID
20#0  ABC-123   IQU
21#1  LFK-402   EUW
22#2  BPM-299   NMS
23data_final_df
24#   IQU_afd  EUW_ote  NMS_qbm
25#0      420       50       50
26#1      380       40       40
27#2      390       45       45
28

I tried the code in Renaming columns of dataframe with values from another dataframe.

It ran without error, but there were no changes. I think column names in data 1 are not perfectly matched to the value in the data2 value.

How can I change some part of the column name from another pandas DataFrame?

ANSWER

Answered 2022-Feb-26 at 12:02

We could create a mapping from "ID" to "NewID" and use it to modify column names:

1data1 = {
2  "ABC-123_afd": [420, 380, 390],
3  "LFK-402_ote": [50, 40, 45],
4  "BPM-299_qbm": [50, 40, 45],
5}
6
7data2 = {
8  "ID": ['ABC-123', 'LFK-402', 'BPM-299'],
9  "NewID": ['IQU', 'EUW', 'NMS']
10}
11
12data1_df=pd.DataFrame(data1)
13#   ABC-123_afd  LFK-402_ote  BPM-299_qbm
14#0          420           50           50
15#1          380           40           40
16#2          390           45           45
17
18data2_df=pd.DataFrame(data2)
19#        ID NewID
20#0  ABC-123   IQU
21#1  LFK-402   EUW
22#2  BPM-299   NMS
23data_final_df
24#   IQU_afd  EUW_ote  NMS_qbm
25#0      420       50       50
26#1      380       40       40
27#2      390       45       45
28mapping = dict(zip(data2['ID'], data2['NewID']))
29data1_df.columns = [mapping[x] + '_' + y for x, y in data1_df.columns.str.split('_')]
30print(data1_df)
31

or

1data1 = {
2  "ABC-123_afd": [420, 380, 390],
3  "LFK-402_ote": [50, 40, 45],
4  "BPM-299_qbm": [50, 40, 45],
5}
6
7data2 = {
8  "ID": ['ABC-123', 'LFK-402', 'BPM-299'],
9  "NewID": ['IQU', 'EUW', 'NMS']
10}
11
12data1_df=pd.DataFrame(data1)
13#   ABC-123_afd  LFK-402_ote  BPM-299_qbm
14#0          420           50           50
15#1          380           40           40
16#2          390           45           45
17
18data2_df=pd.DataFrame(data2)
19#        ID NewID
20#0  ABC-123   IQU
21#1  LFK-402   EUW
22#2  BPM-299   NMS
23data_final_df
24#   IQU_afd  EUW_ote  NMS_qbm
25#0      420       50       50
26#1      380       40       40
27#2      390       45       45
28mapping = dict(zip(data2['ID'], data2['NewID']))
29data1_df.columns = [mapping[x] + '_' + y for x, y in data1_df.columns.str.split('_')]
30print(data1_df)
31s = data1_df.columns.str.split('_')
32data1_df.columns = s.str[0].map(mapping) + '_' + s.str[1]
33

or use the DataFrame data2_df:

1data1 = {
2  "ABC-123_afd": [420, 380, 390],
3  "LFK-402_ote": [50, 40, 45],
4  "BPM-299_qbm": [50, 40, 45],
5}
6
7data2 = {
8  "ID": ['ABC-123', 'LFK-402', 'BPM-299'],
9  "NewID": ['IQU', 'EUW', 'NMS']
10}
11
12data1_df=pd.DataFrame(data1)
13#   ABC-123_afd  LFK-402_ote  BPM-299_qbm
14#0          420           50           50
15#1          380           40           40
16#2          390           45           45
17
18data2_df=pd.DataFrame(data2)
19#        ID NewID
20#0  ABC-123   IQU
21#1  LFK-402   EUW
22#2  BPM-299   NMS
23data_final_df
24#   IQU_afd  EUW_ote  NMS_qbm
25#0      420       50       50
26#1      380       40       40
27#2      390       45       45
28mapping = dict(zip(data2['ID'], data2['NewID']))
29data1_df.columns = [mapping[x] + '_' + y for x, y in data1_df.columns.str.split('_')]
30print(data1_df)
31s = data1_df.columns.str.split('_')
32data1_df.columns = s.str[0].map(mapping) + '_' + s.str[1]
33s = data1_df.columns.str.split('_')
34data1_df.columns = s.str[0].map(data2_df.set_index('ID')['NewID']) + '_' + s.str[1]
35

Output:

1data1 = {
2  "ABC-123_afd": [420, 380, 390],
3  "LFK-402_ote": [50, 40, 45],
4  "BPM-299_qbm": [50, 40, 45],
5}
6
7data2 = {
8  "ID": ['ABC-123', 'LFK-402', 'BPM-299'],
9  "NewID": ['IQU', 'EUW', 'NMS']
10}
11
12data1_df=pd.DataFrame(data1)
13#   ABC-123_afd  LFK-402_ote  BPM-299_qbm
14#0          420           50           50
15#1          380           40           40
16#2          390           45           45
17
18data2_df=pd.DataFrame(data2)
19#        ID NewID
20#0  ABC-123   IQU
21#1  LFK-402   EUW
22#2  BPM-299   NMS
23data_final_df
24#   IQU_afd  EUW_ote  NMS_qbm
25#0      420       50       50
26#1      380       40       40
27#2      390       45       45
28mapping = dict(zip(data2['ID'], data2['NewID']))
29data1_df.columns = [mapping[x] + '_' + y for x, y in data1_df.columns.str.split('_')]
30print(data1_df)
31s = data1_df.columns.str.split('_')
32data1_df.columns = s.str[0].map(mapping) + '_' + s.str[1]
33s = data1_df.columns.str.split('_')
34data1_df.columns = s.str[0].map(data2_df.set_index('ID')['NewID']) + '_' + s.str[1]
35   IQU_afd  EUW_ote  NMS_qbm
360      420       50       50
371      380       40       40
382      390       45       45
39

Source https://stackoverflow.com/questions/71276311

QUESTION

How to separate Camunda tables to a different schema?

Asked 2022-Feb-24 at 05:56

I want to separate Camunda tables to a different schema called camunda but even if I gave the schema-name and table-prefix, it still put all the tables under the public schema.

enter image description here

Here's my application.yml;

1spring:
2  datasource:
3    hikari:
4      pool-name: CAMUNDA-HIKARI-POOL
5      idle-timeout: 3000
6      maximum-pool-size: 10
7      minimum-idle: 30
8      username: ${X_DB_USER:xxxx}
9      password: ${X_DB_PASSWORD:yyyy}
10      connection-timeout: 2000
11      connection-test-query: select 1
12      transaction-isolation: TRANSACTION_READ_COMMITTED
13    driver-class-name: org.postgresql.Driver
14    url: jdbc:postgresql://${X_DB_URL:localhost:5433/x-table?autoReconnect=true}
15  jpa:
16    show-sql: false
17    properties:
18      hibernate:
19        dialect: org.hibernate.dialect.PostgreSQLDialect
20    hibernate:
21      ddl-auto: update
22    open-in-view: false
23    database-platform: org.hibernate.dialect.PostgreSQLDialect
24camunda.bpm:
25  admin-user:
26    id: xxxx
27    password: yyyy
28  metrics:
29    db-reporter-activate: false
30  history-level: full
31  database:
32    schema-update: create-drop
33    schema-name: camunda
34    table-prefix: camunda.
35

What should I do more to let Camunda tables be under the camunda schema?

ANSWER

Answered 2022-Feb-24 at 05:56

Here is a working example for two instance which are using separate database schemas (cam1 and cam2) and not the public schema: https://github.com/rob2universe/two-camunda-instances

Source https://stackoverflow.com/questions/71219044

QUESTION

How to convert json MySQL data into rows and column

Asked 2022-Feb-23 at 09:26

I have mysql table like this which contain id and json type column:

id value
1 {"sys": "20", "dia": "110"}
2 {"bpm": "200"}
3 {"bpm": "123", "sys": "1", "dia": ""}

Now, I want to have a MySQL query to which data should be as below in which id, val1 will contain keys of the json data and val2 will contain values of respective keys :

id val1 val2
1 sys 20
1 dia 110
2 bpm 200
3 bpm 123
3 sys 1
3 dia

Note : I am using MySQL 5.7 version and the keys inside the JSON object are not fixed. It can be any number.

I want to know how I can achieve this using MySQL query

Thanks in Advance!!!

ANSWER

Answered 2022-Feb-18 at 12:01
1CREATE TABLE test (id INT, value JSON);
2INSERT INTO test VALUES
3(1,   '{"sys": "20", "dia": "110"}'),
4(2,   '{"bpm": "200"}'),
5(3,   '{"bpm": "123", "sys": "1", "dia": ""}');
6SELECT id, CAST(value AS CHAR) value FROM test;
7
id value
1 {"dia": "110", "sys": "20"}
2 {"bpm": "200"}
3 {"bpm": "123", "dia": "", "sys": "1"}
1CREATE TABLE test (id INT, value JSON);
2INSERT INTO test VALUES
3(1,   '{"sys": "20", "dia": "110"}'),
4(2,   '{"bpm": "200"}'),
5(3,   '{"bpm": "123", "sys": "1", "dia": ""}');
6SELECT id, CAST(value AS CHAR) value FROM test;
7CREATE PROCEDURE parse_json ()
8BEGIN
9DECLARE counter INT DEFAULT 0;
10CREATE TEMPORARY TABLE tmp1 (id INT, all_keys JSON)
11SELECT id, JSON_KEYS(value) all_keys
12FROM test;
13CREATE TEMPORARY TABLE tmp2 (id INT, one_key VARCHAR(255)) ENGINE = Memory;
14REPEAT
15    INSERT INTO tmp2
16    SELECT id, JSON_EXTRACT(all_keys, CONCAT('$[',counter,']')) one_key
17    FROM tmp1
18    HAVING one_key IS NOT NULL;
19    SET counter := counter + 1;
20UNTIL NOT ROW_COUNT() END REPEAT;
21SELECT id, 
22       CAST(JSON_UNQUOTE(tmp2.one_key) AS CHAR) val1, 
23       CAST(JSON_UNQUOTE(JSON_EXTRACT(test.value, CONCAT('$.', tmp2.one_key))) AS CHAR) val2
24FROM test
25JOIN tmp2 USING (id)
26ORDER BY 1,2;
27DROP TEMPORARY TABLE tmp1;
28DROP TEMPORARY TABLE tmp2;
29END
30
1CREATE TABLE test (id INT, value JSON);
2INSERT INTO test VALUES
3(1,   '{"sys": "20", "dia": "110"}'),
4(2,   '{"bpm": "200"}'),
5(3,   '{"bpm": "123", "sys": "1", "dia": ""}');
6SELECT id, CAST(value AS CHAR) value FROM test;
7CREATE PROCEDURE parse_json ()
8BEGIN
9DECLARE counter INT DEFAULT 0;
10CREATE TEMPORARY TABLE tmp1 (id INT, all_keys JSON)
11SELECT id, JSON_KEYS(value) all_keys
12FROM test;
13CREATE TEMPORARY TABLE tmp2 (id INT, one_key VARCHAR(255)) ENGINE = Memory;
14REPEAT
15    INSERT INTO tmp2
16    SELECT id, JSON_EXTRACT(all_keys, CONCAT('$[',counter,']')) one_key
17    FROM tmp1
18    HAVING one_key IS NOT NULL;
19    SET counter := counter + 1;
20UNTIL NOT ROW_COUNT() END REPEAT;
21SELECT id, 
22       CAST(JSON_UNQUOTE(tmp2.one_key) AS CHAR) val1, 
23       CAST(JSON_UNQUOTE(JSON_EXTRACT(test.value, CONCAT('$.', tmp2.one_key))) AS CHAR) val2
24FROM test
25JOIN tmp2 USING (id)
26ORDER BY 1,2;
27DROP TEMPORARY TABLE tmp1;
28DROP TEMPORARY TABLE tmp2;
29END
30CALL parse_json
31
id val1 val2
1 dia 110
1 sys 20
2 bpm 200
3 bpm 123
3 dia
3 sys 1

db<>fiddle here

If the datatype of the column with JSON values is VARCHAR/TEXT then the data should NOT contain duplicated keys in JSON values.

Source https://stackoverflow.com/questions/71172290

QUESTION

Using pyaudio to build a Metronome; wrong timing

Asked 2022-Feb-08 at 18:29

So I wanted to build a metronome and decided to use pyaudio. I know there are other ways but I want to make something else later with that.

Thats my Code so far:

1
2CHUNK = 1024
3FORMAT = pyaudio.paInt16
4CHANNELS = 2
5RATE = 44100
6def play_audio(filename):
7    wf=wave.open(filename,&quot;rb&quot;)
8    p=pyaudio.PyAudio()
9    stream_play=p.open(format=p.get_format_from_width(wf.getsampwidth()),
10                channels=wf.getnchannels(),
11                rate=wf.getframerate(),
12                output=True)
13    data = wf.readframes(CHUNK)
14    while True:
15        if data != '':
16            stream_play.write(data)
17            data = wf.readframes(CHUNK)
18        if data == b&quot;&quot;:
19            break
20    stream_play.stop_stream()
21    stream_play.close()
22    p.terminate()
23
24def metronom(bpm):
25    while True: 
26        play_callback(beep)
27        time.sleep(60/bpm)
28
29beep=&quot;beep-07a.wav&quot;
30
31
32
33

I thought it worked out, but unfortunately the timing is completely off. I also tried it with a callback function, but had the same wrong timing.

THE SOLUTION NOW LOOKS LIKE THIS

1
2CHUNK = 1024
3FORMAT = pyaudio.paInt16
4CHANNELS = 2
5RATE = 44100
6def play_audio(filename):
7    wf=wave.open(filename,&quot;rb&quot;)
8    p=pyaudio.PyAudio()
9    stream_play=p.open(format=p.get_format_from_width(wf.getsampwidth()),
10                channels=wf.getnchannels(),
11                rate=wf.getframerate(),
12                output=True)
13    data = wf.readframes(CHUNK)
14    while True:
15        if data != '':
16            stream_play.write(data)
17            data = wf.readframes(CHUNK)
18        if data == b&quot;&quot;:
19            break
20    stream_play.stop_stream()
21    stream_play.close()
22    p.terminate()
23
24def metronom(bpm):
25    while True: 
26        play_callback(beep)
27        time.sleep(60/bpm)
28
29beep=&quot;beep-07a.wav&quot;
30
31
32
33def metronom(bpm):
34    while True: 
35        startTime = time.time()
36        play_callback(beep)
37        endTime=time.time()-startTime
38        time.sleep(60/bpm-endTime)
39

ANSWER

Answered 2022-Feb-08 at 18:16

You want the play_audio function to be called every 60/bpm seconds, but the function call itself takes time: you need to read the file, open the stream, play the file (who knows how long it is) and close the stream. So that adds to the time from one click to the next.

To fix this problem, you could try subtracting the time it takes to run the play_audio function from the time you sleep. You could also experiment with running play_audio on a separate thread.

Source https://stackoverflow.com/questions/71038624

QUESTION

Why am I getting &quot;Error processing transaction request: intrinsic gas too low&quot; error when trying to add tUSDT to a particular account?

Asked 2022-Jan-04 at 18:26

I am trying to send test USDT to a particular account in Java using the following code:

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6

The last statement results in the following exception:

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17

TestGasProvider is defined as:

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17public class TestGasProvider extends StaticGasProvider {
18    public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
19    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
20
21    public TestGasProvider() {
22        super(GAS_PRICE, GAS_LIMIT);
23    }
24}
25

usdtContract was deployed using this script, which calls deploy.js:

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17public class TestGasProvider extends StaticGasProvider {
18    public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
19    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
20
21    public TestGasProvider() {
22        super(GAS_PRICE, GAS_LIMIT);
23    }
24}
25async function main() {
26  const USDT = await ethers.getContractFactory(&quot;USDT&quot;);
27  const usdt = await USDT.deploy(1000000000000000);
28
29  console.log(&quot;USDT contract deployed to:&quot;, usdt.address);
30}
31
32main()
33  .then(() =&gt; process.exit(0))
34  .catch((error) =&gt; {
35    console.error(error);
36    process.exit(1);
37  });
38

This contract is running on a local testnet set up as described here.

What do I need to change in any of these components (testnet, contract, deploy scripts, Java code) in order to send any amount of USDT to a particular address (without any errors)?

Update 1: If I change TestGasProvider to

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17public class TestGasProvider extends StaticGasProvider {
18    public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
19    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
20
21    public TestGasProvider() {
22        super(GAS_PRICE, GAS_LIMIT);
23    }
24}
25async function main() {
26  const USDT = await ethers.getContractFactory(&quot;USDT&quot;);
27  const usdt = await USDT.deploy(1000000000000000);
28
29  console.log(&quot;USDT contract deployed to:&quot;, usdt.address);
30}
31
32main()
33  .then(() =&gt; process.exit(0))
34  .catch((error) =&gt; {
35    console.error(error);
36    process.exit(1);
37  });
38public class TestGasProvider extends StaticGasProvider {
39    public static final BigInteger GAS_PRICE = BigInteger.valueOf(1L);
40    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1000000000L);
41
42    public TestGasProvider() {
43        super(GAS_PRICE, GAS_LIMIT);
44    }
45}
46
47

I get another error:

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17public class TestGasProvider extends StaticGasProvider {
18    public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
19    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
20
21    public TestGasProvider() {
22        super(GAS_PRICE, GAS_LIMIT);
23    }
24}
25async function main() {
26  const USDT = await ethers.getContractFactory(&quot;USDT&quot;);
27  const usdt = await USDT.deploy(1000000000000000);
28
29  console.log(&quot;USDT contract deployed to:&quot;, usdt.address);
30}
31
32main()
33  .then(() =&gt; process.exit(0))
34  .catch((error) =&gt; {
35    console.error(error);
36    process.exit(1);
37  });
38public class TestGasProvider extends StaticGasProvider {
39    public static final BigInteger GAS_PRICE = BigInteger.valueOf(1L);
40    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1000000000L);
41
42    public TestGasProvider() {
43        super(GAS_PRICE, GAS_LIMIT);
44    }
45}
46
47java.lang.RuntimeException: Error processing transaction request: exceeds block gas limit
48    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
49    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
50    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
51    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
52    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
53    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
54    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
55    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
56    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
57    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
58
59
Terms for the bounty

I will award the bounty to a person who submits a set of code changes to the branch i16 of the minimal-crypto-exchange project which pass the following test:

Step 1

Set up the environment as described here.

Step 2

Set a breakpoint on line usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send(); in TransferUsdtToExchangeAccount class:

Screenshot of the code part with breakpoint

Step 3

Start the process engine application in debug mode. Its Java main method is located here.

Wait until you see the message starting to acquire jobs in the console output:

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17public class TestGasProvider extends StaticGasProvider {
18    public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
19    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
20
21    public TestGasProvider() {
22        super(GAS_PRICE, GAS_LIMIT);
23    }
24}
25async function main() {
26  const USDT = await ethers.getContractFactory(&quot;USDT&quot;);
27  const usdt = await USDT.deploy(1000000000000000);
28
29  console.log(&quot;USDT contract deployed to:&quot;, usdt.address);
30}
31
32main()
33  .then(() =&gt; process.exit(0))
34  .catch((error) =&gt; {
35    console.error(error);
36    process.exit(1);
37  });
38public class TestGasProvider extends StaticGasProvider {
39    public static final BigInteger GAS_PRICE = BigInteger.valueOf(1L);
40    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1000000000L);
41
42    public TestGasProvider() {
43        super(GAS_PRICE, GAS_LIMIT);
44    }
45}
46
47java.lang.RuntimeException: Error processing transaction request: exceeds block gas limit
48    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
49    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
50    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
51    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
52    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
53    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
54    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
55    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
56    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
57    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
58
5911:59:16.031 [JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor]] INFO  org.camunda.bpm.engine.jobexecutor - ENGINE-14018 JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor] starting to acquire jobs
60
Step 4

Login with the credentials demo/demo at http://localhost:8080.

Screenshot of the login form

After login you should see a page like this:

Main Camunda dashboard with tasklist link highlighted

Step 5

Click on the tasklist link. You should see a page that looks like this:

"Start process" link the tasklist

Press the "Start process" link. Following screen will appear:

"Start process" dialog box with "Send USDT to the exchange account" process highlighted

Click on Send USDT to the exchange account process link. Following dialog box will appear:

"Start process" dialog

Enter an arbitrary value into the "business key" field and press the "Start" button.

Step 6

After a couple of seconds, the breakpoint from step 2 will activate.

The conditions for granting the bounty are satisfied, if usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send(); is executed without errors.

Notes
  1. You are allowed to modify the amount in usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send(); from 10 to something else.
  2. You can also modify the parameters of the Ethereum testnet specified in docker-compose.yml and genesis.json, as well as those of the USDT smart contract which is deployed using this script.
  3. Your solution must work in this controlled environment (i. e. no faucets must be used).
Update 2 (2021-12-31)

I made following changes:

  1. The set-up tutorial now contains step 7 in which ETH is added to the exchange account.
  2. Now a new version of the ETH testnet is being used, major changes being that log output is more verbose and the gas price is set to 1 (see --miner.gasprice 1 in entrypoint.sh).
  3. Modified the code in TransferUsdtToExchangeAccount so that now USDT is transferred not from the exchange account (which has zero balance), but from the buffer account.

Now I am receiving the error

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17public class TestGasProvider extends StaticGasProvider {
18    public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
19    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
20
21    public TestGasProvider() {
22        super(GAS_PRICE, GAS_LIMIT);
23    }
24}
25async function main() {
26  const USDT = await ethers.getContractFactory(&quot;USDT&quot;);
27  const usdt = await USDT.deploy(1000000000000000);
28
29  console.log(&quot;USDT contract deployed to:&quot;, usdt.address);
30}
31
32main()
33  .then(() =&gt; process.exit(0))
34  .catch((error) =&gt; {
35    console.error(error);
36    process.exit(1);
37  });
38public class TestGasProvider extends StaticGasProvider {
39    public static final BigInteger GAS_PRICE = BigInteger.valueOf(1L);
40    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1000000000L);
41
42    public TestGasProvider() {
43        super(GAS_PRICE, GAS_LIMIT);
44    }
45}
46
47java.lang.RuntimeException: Error processing transaction request: exceeds block gas limit
48    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
49    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
50    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
51    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
52    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
53    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
54    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
55    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
56    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
57    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
58
5911:59:16.031 [JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor]] INFO  org.camunda.bpm.engine.jobexecutor - ENGINE-14018 JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor] starting to acquire jobs
60org.web3j.protocol.exceptions.TransactionException: Transaction 0x4bce379a2673c4564b2eb6080607b00d1a8ac232fbddf903f353f4eeda566cae
61has failed with status: 0x0. Gas used: 32767. 
62Revert reason: 'ERC20: transfer amount exceeds allowance'.
63

ANSWER

Answered 2022-Jan-04 at 18:26

My skills with Ethereum are still not sharp enough to give you a proper answer, but I hope you get some guidance.

The error states that you are trying to transfer by a party A certain quantity in the name of another party B, to a third one C, but the amount you are trying to transfer, using transferFrom, is greater than the one party B approved party A to send.

You can check the actual allowance between to parties using the method with the same name of your contract.

Please, consider review this integration test from the web3j library in Github. It is different than yours but I think it could be helpful.

Especially, it states that the actual transferFrom operation should be performed by the beneficiary of the allowance. Please, see the relevant code:

1final Web3j web3 = createWeb3If(ethNetworkUrl);
2final Credentials credentials = Credentials.create(privateKey);
3final ERC20 usdtContract = ERC20.load(usdtContractAddress, web3, credentials, new TestGasProvider());
4
5usdtContract.transfer(exchangeAddress, BigInteger.valueOf(10)).send();
6java.lang.RuntimeException: Error processing transaction request: intrinsic gas too low
7    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
8    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
9    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
10    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
11    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
12    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
13    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
14    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
15    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
16    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
17public class TestGasProvider extends StaticGasProvider {
18    public static final BigInteger GAS_PRICE = BigInteger.valueOf(10L);
19    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1L);
20
21    public TestGasProvider() {
22        super(GAS_PRICE, GAS_LIMIT);
23    }
24}
25async function main() {
26  const USDT = await ethers.getContractFactory(&quot;USDT&quot;);
27  const usdt = await USDT.deploy(1000000000000000);
28
29  console.log(&quot;USDT contract deployed to:&quot;, usdt.address);
30}
31
32main()
33  .then(() =&gt; process.exit(0))
34  .catch((error) =&gt; {
35    console.error(error);
36    process.exit(1);
37  });
38public class TestGasProvider extends StaticGasProvider {
39    public static final BigInteger GAS_PRICE = BigInteger.valueOf(1L);
40    public static final BigInteger GAS_LIMIT = BigInteger.valueOf(1000000000L);
41
42    public TestGasProvider() {
43        super(GAS_PRICE, GAS_LIMIT);
44    }
45}
46
47java.lang.RuntimeException: Error processing transaction request: exceeds block gas limit
48    at org.web3j.tx.TransactionManager.processResponse(TransactionManager.java:176)
49    at org.web3j.tx.TransactionManager.executeTransaction(TransactionManager.java:81)
50    at org.web3j.tx.ManagedTransaction.send(ManagedTransaction.java:128)
51    at org.web3j.tx.Contract.executeTransaction(Contract.java:367)
52    at org.web3j.tx.Contract.executeTransaction(Contract.java:350)
53    at org.web3j.tx.Contract.executeTransaction(Contract.java:344)
54    at org.web3j.tx.Contract.executeTransaction(Contract.java:339)
55    at org.web3j.tx.Contract.lambda$executeRemoteCallTransaction$3(Contract.java:410)
56    at org.web3j.protocol.core.RemoteCall.send(RemoteCall.java:42)
57    at com.dpisarenko.minimalcryptoexchange.delegates.TransferUsdtToExchangeAccount.execute(TransferUsdtToExchangeAccount.java:57)
58
5911:59:16.031 [JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor]] INFO  org.camunda.bpm.engine.jobexecutor - ENGINE-14018 JobExecutor[org.camunda.bpm.engine.spring.components.jobexecutor.SpringJobExecutor] starting to acquire jobs
60org.web3j.protocol.exceptions.TransactionException: Transaction 0x4bce379a2673c4564b2eb6080607b00d1a8ac232fbddf903f353f4eeda566cae
61has failed with status: 0x0. Gas used: 32767. 
62Revert reason: 'ERC20: transfer amount exceeds allowance'.
63final String aliceAddress = ALICE.getAddress();
64final String bobAddress = BOB.getAddress();
65ContractGasProvider contractGasProvider = new DefaultGasProvider();
66HumanStandardToken contract =
67        HumanStandardToken.deploy(
68                        web3j,
69                        ALICE,
70                        contractGasProvider,
71                        aliceQty,
72                        &quot;web3j tokens&quot;,
73                        BigInteger.valueOf(18),
74                        &quot;w3j$&quot;)
75                .send();
76
77//...
78
79// set an allowance
80assertEquals(contract.allowance(aliceAddress, bobAddress).send(), (BigInteger.ZERO));
81
82transferQuantity = BigInteger.valueOf(50);
83TransactionReceipt approveReceipt =
84        contract.approve(BOB.getAddress(), transferQuantity).send();
85
86HumanStandardToken.ApprovalEventResponse approvalEventValues =
87        contract.getApprovalEvents(approveReceipt).get(0);
88
89assertEquals(approvalEventValues._owner, (aliceAddress));
90assertEquals(approvalEventValues._spender, (bobAddress));
91assertEquals(approvalEventValues._value, (transferQuantity));
92
93assertEquals(contract.allowance(aliceAddress, bobAddress).send(), (transferQuantity));
94
95// perform a transfer as Bob
96transferQuantity = BigInteger.valueOf(25);
97
98// Bob requires his own contract instance
99HumanStandardToken bobsContract =
100        HumanStandardToken.load(
101                contract.getContractAddress(), web3j, BOB, STATIC_GAS_PROVIDER);
102
103TransactionReceipt bobTransferReceipt =
104        bobsContract.transferFrom(aliceAddress, bobAddress, transferQuantity).send();
105
106HumanStandardToken.TransferEventResponse bobTransferEventValues =
107        contract.getTransferEvents(bobTransferReceipt).get(0);
108assertEquals(bobTransferEventValues._from, (aliceAddress));
109assertEquals(bobTransferEventValues._to, (bobAddress));
110assertEquals(bobTransferEventValues._value, (transferQuantity));
111
112//...
113

This fact is also indicated in this OpenZeppelin forum post.

Source https://stackoverflow.com/questions/70483315

QUESTION

getting a KeyNotFoundException on a key that appears to exist in a dictionary

Asked 2021-Dec-25 at 22:29

full error:

1KeyNotFoundException: The given key was not present in the dictionary.
2System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at &lt;695d1cc93cca45069c528c15c9fdd749&gt;:0)
3TonePlayer+&lt;lightUp&gt;d__6.MoveNext () (at Assets/TonePlayer.cs:43)
4UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at &lt;0ee480759f3d481d82ada245dc74f9fd&gt;:0)
5UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
6TonePlayer:Awake() (at Assets/TonePlayer.cs:14)
7

when i check the value of the timing array (TonePlayer) and compare it to the value of the timings array (SongManager) their values appear to be the same, but are not recognized as the same value I have tried printing the array's contents and the contents were identical.

both arrays are of the same type (string) and each element is a float converted to a string with 3 decimal places

the .unf file is just a midi converted to json, here are its contents:

1KeyNotFoundException: The given key was not present in the dictionary.
2System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at &lt;695d1cc93cca45069c528c15c9fdd749&gt;:0)
3TonePlayer+&lt;lightUp&gt;d__6.MoveNext () (at Assets/TonePlayer.cs:43)
4UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at &lt;0ee480759f3d481d82ada245dc74f9fd&gt;:0)
5UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
6TonePlayer:Awake() (at Assets/TonePlayer.cs:14)
7{
8  &quot;header&quot;: {
9    &quot;PPQ&quot;: 480,
10    &quot;timeSignature&quot;: [
11      4,
12      4
13    ],
14    &quot;bpm&quot;: 120,
15    &quot;name&quot;: &quot;Piano&quot;
16  },
17  &quot;tempo&quot;: [
18    {
19      &quot;absoluteTime&quot;: 0,
20      &quot;seconds&quot;: 0,
21      &quot;bpm&quot;: 120
22    }
23  ],
24  &quot;timeSignature&quot;: [
25    {
26      &quot;absoluteTime&quot;: 0,
27      &quot;seconds&quot;: 0,
28      &quot;numerator&quot;: 4,
29      &quot;denominator&quot;: 2,
30      &quot;click&quot;: 24,
31      &quot;notesQ&quot;: 8
32    }
33  ],
34  &quot;startTime&quot;: 0,
35  &quot;duration&quot;: 9.223958333333334,
36  &quot;tracks&quot;: [
37    {
38      &quot;startTime&quot;: 0,
39      &quot;duration&quot;: 9.223958333333334,
40      &quot;length&quot;: 26,
41      &quot;notes&quot;: [
42        {
43          &quot;name&quot;: &quot;E5&quot;,
44          &quot;midi&quot;: 76,
45          &quot;time&quot;: 0,
46          &quot;velocity&quot;: 0.6299212598425197,
47          &quot;duration&quot;: 0.23645833333333333
48        },
49        {
50          &quot;name&quot;: &quot;E5&quot;,
51          &quot;midi&quot;: 76,
52          &quot;time&quot;: 0.25,
53          &quot;velocity&quot;: 0.6299212598425197,
54          &quot;duration&quot;: 0.23645833333333333
55        },
56        {
57          &quot;name&quot;: &quot;E5&quot;,
58          &quot;midi&quot;: 76,
59          &quot;time&quot;: 0.5,
60          &quot;velocity&quot;: 0.6299212598425197,
61          &quot;duration&quot;: 0.23645833333333333
62        },
63        {
64          &quot;name&quot;: &quot;C5&quot;,
65          &quot;midi&quot;: 72,
66          &quot;time&quot;: 0.75,
67          &quot;velocity&quot;: 0.6299212598425197,
68          &quot;duration&quot;: 0.23645833333333333
69        },
70        {
71          &quot;name&quot;: &quot;C5&quot;,
72          &quot;midi&quot;: 72,
73          &quot;time&quot;: 1,
74          &quot;velocity&quot;: 0.6299212598425197,
75          &quot;duration&quot;: 0.23645833333333321
76        },
77        {
78          &quot;name&quot;: &quot;C5&quot;,
79          &quot;midi&quot;: 72,
80          &quot;time&quot;: 1.2499999999999998,
81          &quot;velocity&quot;: 0.6299212598425197,
82          &quot;duration&quot;: 0.47395833333333326
83        },
84        {
85          &quot;name&quot;: &quot;C5&quot;,
86          &quot;midi&quot;: 72,
87          &quot;time&quot;: 1.9999999999999998,
88          &quot;velocity&quot;: 0.6299212598425197,
89          &quot;duration&quot;: 0.23645833333333344
90        },
91        {
92          &quot;name&quot;: &quot;D5&quot;,
93          &quot;midi&quot;: 74,
94          &quot;time&quot;: 2.25,
95          &quot;velocity&quot;: 0.6299212598425197,
96          &quot;duration&quot;: 0.23645833333333321
97        },
98        {
99          &quot;name&quot;: &quot;F5&quot;,
100          &quot;midi&quot;: 77,
101          &quot;time&quot;: 2.5,
102          &quot;velocity&quot;: 0.6299212598425197,
103          &quot;duration&quot;: 0.4739583333333335
104        },
105        {
106          &quot;name&quot;: &quot;E5&quot;,
107          &quot;midi&quot;: 76,
108          &quot;time&quot;: 3,
109          &quot;velocity&quot;: 0.6299212598425197,
110          &quot;duration&quot;: 0.4739583333333335
111        },
112        {
113          &quot;name&quot;: &quot;D5&quot;,
114          &quot;midi&quot;: 74,
115          &quot;time&quot;: 3.5,
116          &quot;velocity&quot;: 0.6299212598425197,
117          &quot;duration&quot;: 0.23645833333333321
118        },
119        {
120          &quot;name&quot;: &quot;C5&quot;,
121          &quot;midi&quot;: 72,
122          &quot;time&quot;: 3.75,
123          &quot;velocity&quot;: 0.6299212598425197,
124          &quot;duration&quot;: 0.23645833333333321
125        },
126        {
127          &quot;name&quot;: &quot;E5&quot;,
128          &quot;midi&quot;: 76,
129          &quot;time&quot;: 4,
130          &quot;velocity&quot;: 0.6299212598425197,
131          &quot;duration&quot;: 0.23645833333333321
132        },
133        {
134          &quot;name&quot;: &quot;E5&quot;,
135          &quot;midi&quot;: 76,
136          &quot;time&quot;: 4.25,
137          &quot;velocity&quot;: 0.6299212598425197,
138          &quot;duration&quot;: 0.23645833333333321
139        },
140        {
141          &quot;name&quot;: &quot;E5&quot;,
142          &quot;midi&quot;: 76,
143          &quot;time&quot;: 4.5,
144          &quot;velocity&quot;: 0.6299212598425197,
145          &quot;duration&quot;: 0.23645833333333321
146        },
147        {
148          &quot;name&quot;: &quot;C5&quot;,
149          &quot;midi&quot;: 72,
150          &quot;time&quot;: 4.75,
151          &quot;velocity&quot;: 0.6299212598425197,
152          &quot;duration&quot;: 0.23645833333333321
153        },
154        {
155          &quot;name&quot;: &quot;C5&quot;,
156          &quot;midi&quot;: 72,
157          &quot;time&quot;: 5,
158          &quot;velocity&quot;: 0.6299212598425197,
159          &quot;duration&quot;: 0.23645833333333321
160        },
161        {
162          &quot;name&quot;: &quot;C5&quot;,
163          &quot;midi&quot;: 72,
164          &quot;time&quot;: 5.25,
165          &quot;velocity&quot;: 0.6299212598425197,
166          &quot;duration&quot;: 0.47395833333333304
167        },
168        {
169          &quot;name&quot;: &quot;D5&quot;,
170          &quot;midi&quot;: 74,
171          &quot;time&quot;: 6.75,
172          &quot;velocity&quot;: 0.6299212598425197,
173          &quot;duration&quot;: 0.23645833333333321
174        },
175        {
176          &quot;name&quot;: &quot;D5&quot;,
177          &quot;midi&quot;: 74,
178          &quot;time&quot;: 7,
179          &quot;velocity&quot;: 0.6299212598425197,
180          &quot;duration&quot;: 0.23645833333333321
181        },
182        {
183          &quot;name&quot;: &quot;D5&quot;,
184          &quot;midi&quot;: 74,
185          &quot;time&quot;: 7.25,
186          &quot;velocity&quot;: 0.6299212598425197,
187          &quot;duration&quot;: 0.23645833333333321
188        },
189        {
190          &quot;name&quot;: &quot;D5&quot;,
191          &quot;midi&quot;: 74,
192          &quot;time&quot;: 7.5,
193          &quot;velocity&quot;: 0.6299212598425197,
194          &quot;duration&quot;: 0.23645833333333321
195        },
196        {
197          &quot;name&quot;: &quot;D5&quot;,
198          &quot;midi&quot;: 74,
199          &quot;time&quot;: 7.75,
200          &quot;velocity&quot;: 0.6299212598425197,
201          &quot;duration&quot;: 0.23645833333333321
202        },
203        {
204          &quot;name&quot;: &quot;C5&quot;,
205          &quot;midi&quot;: 72,
206          &quot;time&quot;: 8,
207          &quot;velocity&quot;: 0.6299212598425197,
208          &quot;duration&quot;: 0.23645833333333321
209        },
210        {
211          &quot;name&quot;: &quot;D5&quot;,
212          &quot;midi&quot;: 74,
213          &quot;time&quot;: 8.25,
214          &quot;velocity&quot;: 0.6299212598425197,
215          &quot;duration&quot;: 0.4739583333333339
216        },
217        {
218          &quot;name&quot;: &quot;E5&quot;,
219          &quot;midi&quot;: 76,
220          &quot;time&quot;: 8.75,
221          &quot;velocity&quot;: 0.6299212598425197,
222          &quot;duration&quot;: 0.4739583333333339
223        }
224      ],
225      &quot;controlChanges&quot;: {
226        &quot;7&quot;: [
227          {
228            &quot;number&quot;: 7,
229            &quot;time&quot;: 0,
230            &quot;value&quot;: 0.7874015748031497
231          }
232        ],
233        &quot;10&quot;: [
234          {
235            &quot;number&quot;: 10,
236            &quot;time&quot;: 0,
237            &quot;value&quot;: 0.5039370078740157
238          }
239        ],
240        &quot;91&quot;: [
241          {
242            &quot;number&quot;: 91,
243            &quot;time&quot;: 0,
244            &quot;value&quot;: 0
245          }
246        ],
247        &quot;93&quot;: [
248          {
249            &quot;number&quot;: 93,
250            &quot;time&quot;: 0,
251            &quot;value&quot;: 0
252          }
253        ],
254        &quot;121&quot;: [
255          {
256            &quot;number&quot;: 121,
257            &quot;time&quot;: 0,
258            &quot;value&quot;: 0
259          }
260        ]
261      },
262      &quot;id&quot;: 0,
263      &quot;name&quot;: &quot;Piano&quot;,
264      &quot;instrumentNumber&quot;: 0,
265      &quot;instrument&quot;: &quot;acoustic grand piano&quot;,
266      &quot;instrumentFamily&quot;: &quot;piano&quot;,
267      &quot;channelNumber&quot;: 0,
268      &quot;isPercussion&quot;: false
269    },
270    {
271      &quot;startTime&quot;: 0,
272      &quot;duration&quot;: 0,
273      &quot;length&quot;: 0,
274      &quot;notes&quot;: [],
275      &quot;controlChanges&quot;: {},
276      &quot;id&quot;: 1,
277      &quot;name&quot;: &quot;Piano&quot;
278    }
279  ]
280}
281

output (first loop): timings (SongManager): 0,000, 0,236 timing (TonePlayer): 0,000, 0,236

TonePlayer.cs:

1KeyNotFoundException: The given key was not present in the dictionary.
2System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at &lt;695d1cc93cca45069c528c15c9fdd749&gt;:0)
3TonePlayer+&lt;lightUp&gt;d__6.MoveNext () (at Assets/TonePlayer.cs:43)
4UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at &lt;0ee480759f3d481d82ada245dc74f9fd&gt;:0)
5UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
6TonePlayer:Awake() (at Assets/TonePlayer.cs:14)
7{
8  &quot;header&quot;: {
9    &quot;PPQ&quot;: 480,
10    &quot;timeSignature&quot;: [
11      4,
12      4
13    ],
14    &quot;bpm&quot;: 120,
15    &quot;name&quot;: &quot;Piano&quot;
16  },
17  &quot;tempo&quot;: [
18    {
19      &quot;absoluteTime&quot;: 0,
20      &quot;seconds&quot;: 0,
21      &quot;bpm&quot;: 120
22    }
23  ],
24  &quot;timeSignature&quot;: [
25    {
26      &quot;absoluteTime&quot;: 0,
27      &quot;seconds&quot;: 0,
28      &quot;numerator&quot;: 4,
29      &quot;denominator&quot;: 2,
30      &quot;click&quot;: 24,
31      &quot;notesQ&quot;: 8
32    }
33  ],
34  &quot;startTime&quot;: 0,
35  &quot;duration&quot;: 9.223958333333334,
36  &quot;tracks&quot;: [
37    {
38      &quot;startTime&quot;: 0,
39      &quot;duration&quot;: 9.223958333333334,
40      &quot;length&quot;: 26,
41      &quot;notes&quot;: [
42        {
43          &quot;name&quot;: &quot;E5&quot;,
44          &quot;midi&quot;: 76,
45          &quot;time&quot;: 0,
46          &quot;velocity&quot;: 0.6299212598425197,
47          &quot;duration&quot;: 0.23645833333333333
48        },
49        {
50          &quot;name&quot;: &quot;E5&quot;,
51          &quot;midi&quot;: 76,
52          &quot;time&quot;: 0.25,
53          &quot;velocity&quot;: 0.6299212598425197,
54          &quot;duration&quot;: 0.23645833333333333
55        },
56        {
57          &quot;name&quot;: &quot;E5&quot;,
58          &quot;midi&quot;: 76,
59          &quot;time&quot;: 0.5,
60          &quot;velocity&quot;: 0.6299212598425197,
61          &quot;duration&quot;: 0.23645833333333333
62        },
63        {
64          &quot;name&quot;: &quot;C5&quot;,
65          &quot;midi&quot;: 72,
66          &quot;time&quot;: 0.75,
67          &quot;velocity&quot;: 0.6299212598425197,
68          &quot;duration&quot;: 0.23645833333333333
69        },
70        {
71          &quot;name&quot;: &quot;C5&quot;,
72          &quot;midi&quot;: 72,
73          &quot;time&quot;: 1,
74          &quot;velocity&quot;: 0.6299212598425197,
75          &quot;duration&quot;: 0.23645833333333321
76        },
77        {
78          &quot;name&quot;: &quot;C5&quot;,
79          &quot;midi&quot;: 72,
80          &quot;time&quot;: 1.2499999999999998,
81          &quot;velocity&quot;: 0.6299212598425197,
82          &quot;duration&quot;: 0.47395833333333326
83        },
84        {
85          &quot;name&quot;: &quot;C5&quot;,
86          &quot;midi&quot;: 72,
87          &quot;time&quot;: 1.9999999999999998,
88          &quot;velocity&quot;: 0.6299212598425197,
89          &quot;duration&quot;: 0.23645833333333344
90        },
91        {
92          &quot;name&quot;: &quot;D5&quot;,
93          &quot;midi&quot;: 74,
94          &quot;time&quot;: 2.25,
95          &quot;velocity&quot;: 0.6299212598425197,
96          &quot;duration&quot;: 0.23645833333333321
97        },
98        {
99          &quot;name&quot;: &quot;F5&quot;,
100          &quot;midi&quot;: 77,
101          &quot;time&quot;: 2.5,
102          &quot;velocity&quot;: 0.6299212598425197,
103          &quot;duration&quot;: 0.4739583333333335
104        },
105        {
106          &quot;name&quot;: &quot;E5&quot;,
107          &quot;midi&quot;: 76,
108          &quot;time&quot;: 3,
109          &quot;velocity&quot;: 0.6299212598425197,
110          &quot;duration&quot;: 0.4739583333333335
111        },
112        {
113          &quot;name&quot;: &quot;D5&quot;,
114          &quot;midi&quot;: 74,
115          &quot;time&quot;: 3.5,
116          &quot;velocity&quot;: 0.6299212598425197,
117          &quot;duration&quot;: 0.23645833333333321
118        },
119        {
120          &quot;name&quot;: &quot;C5&quot;,
121          &quot;midi&quot;: 72,
122          &quot;time&quot;: 3.75,
123          &quot;velocity&quot;: 0.6299212598425197,
124          &quot;duration&quot;: 0.23645833333333321
125        },
126        {
127          &quot;name&quot;: &quot;E5&quot;,
128          &quot;midi&quot;: 76,
129          &quot;time&quot;: 4,
130          &quot;velocity&quot;: 0.6299212598425197,
131          &quot;duration&quot;: 0.23645833333333321
132        },
133        {
134          &quot;name&quot;: &quot;E5&quot;,
135          &quot;midi&quot;: 76,
136          &quot;time&quot;: 4.25,
137          &quot;velocity&quot;: 0.6299212598425197,
138          &quot;duration&quot;: 0.23645833333333321
139        },
140        {
141          &quot;name&quot;: &quot;E5&quot;,
142          &quot;midi&quot;: 76,
143          &quot;time&quot;: 4.5,
144          &quot;velocity&quot;: 0.6299212598425197,
145          &quot;duration&quot;: 0.23645833333333321
146        },
147        {
148          &quot;name&quot;: &quot;C5&quot;,
149          &quot;midi&quot;: 72,
150          &quot;time&quot;: 4.75,
151          &quot;velocity&quot;: 0.6299212598425197,
152          &quot;duration&quot;: 0.23645833333333321
153        },
154        {
155          &quot;name&quot;: &quot;C5&quot;,
156          &quot;midi&quot;: 72,
157          &quot;time&quot;: 5,
158          &quot;velocity&quot;: 0.6299212598425197,
159          &quot;duration&quot;: 0.23645833333333321
160        },
161        {
162          &quot;name&quot;: &quot;C5&quot;,
163          &quot;midi&quot;: 72,
164          &quot;time&quot;: 5.25,
165          &quot;velocity&quot;: 0.6299212598425197,
166          &quot;duration&quot;: 0.47395833333333304
167        },
168        {
169          &quot;name&quot;: &quot;D5&quot;,
170          &quot;midi&quot;: 74,
171          &quot;time&quot;: 6.75,
172          &quot;velocity&quot;: 0.6299212598425197,
173          &quot;duration&quot;: 0.23645833333333321
174        },
175        {
176          &quot;name&quot;: &quot;D5&quot;,
177          &quot;midi&quot;: 74,
178          &quot;time&quot;: 7,
179          &quot;velocity&quot;: 0.6299212598425197,
180          &quot;duration&quot;: 0.23645833333333321
181        },
182        {
183          &quot;name&quot;: &quot;D5&quot;,
184          &quot;midi&quot;: 74,
185          &quot;time&quot;: 7.25,
186          &quot;velocity&quot;: 0.6299212598425197,
187          &quot;duration&quot;: 0.23645833333333321
188        },
189        {
190          &quot;name&quot;: &quot;D5&quot;,
191          &quot;midi&quot;: 74,
192          &quot;time&quot;: 7.5,
193          &quot;velocity&quot;: 0.6299212598425197,
194          &quot;duration&quot;: 0.23645833333333321
195        },
196        {
197          &quot;name&quot;: &quot;D5&quot;,
198          &quot;midi&quot;: 74,
199          &quot;time&quot;: 7.75,
200          &quot;velocity&quot;: 0.6299212598425197,
201          &quot;duration&quot;: 0.23645833333333321
202        },
203        {
204          &quot;name&quot;: &quot;C5&quot;,
205          &quot;midi&quot;: 72,
206          &quot;time&quot;: 8,
207          &quot;velocity&quot;: 0.6299212598425197,
208          &quot;duration&quot;: 0.23645833333333321
209        },
210        {
211          &quot;name&quot;: &quot;D5&quot;,
212          &quot;midi&quot;: 74,
213          &quot;time&quot;: 8.25,
214          &quot;velocity&quot;: 0.6299212598425197,
215          &quot;duration&quot;: 0.4739583333333339
216        },
217        {
218          &quot;name&quot;: &quot;E5&quot;,
219          &quot;midi&quot;: 76,
220          &quot;time&quot;: 8.75,
221          &quot;velocity&quot;: 0.6299212598425197,
222          &quot;duration&quot;: 0.4739583333333339
223        }
224      ],
225      &quot;controlChanges&quot;: {
226        &quot;7&quot;: [
227          {
228            &quot;number&quot;: 7,
229            &quot;time&quot;: 0,
230            &quot;value&quot;: 0.7874015748031497
231          }
232        ],
233        &quot;10&quot;: [
234          {
235            &quot;number&quot;: 10,
236            &quot;time&quot;: 0,
237            &quot;value&quot;: 0.5039370078740157
238          }
239        ],
240        &quot;91&quot;: [
241          {
242            &quot;number&quot;: 91,
243            &quot;time&quot;: 0,
244            &quot;value&quot;: 0
245          }
246        ],
247        &quot;93&quot;: [
248          {
249            &quot;number&quot;: 93,
250            &quot;time&quot;: 0,
251            &quot;value&quot;: 0
252          }
253        ],
254        &quot;121&quot;: [
255          {
256            &quot;number&quot;: 121,
257            &quot;time&quot;: 0,
258            &quot;value&quot;: 0
259          }
260        ]
261      },
262      &quot;id&quot;: 0,
263      &quot;name&quot;: &quot;Piano&quot;,
264      &quot;instrumentNumber&quot;: 0,
265      &quot;instrument&quot;: &quot;acoustic grand piano&quot;,
266      &quot;instrumentFamily&quot;: &quot;piano&quot;,
267      &quot;channelNumber&quot;: 0,
268      &quot;isPercussion&quot;: false
269    },
270    {
271      &quot;startTime&quot;: 0,
272      &quot;duration&quot;: 0,
273      &quot;length&quot;: 0,
274      &quot;notes&quot;: [],
275      &quot;controlChanges&quot;: {},
276      &quot;id&quot;: 1,
277      &quot;name&quot;: &quot;Piano&quot;
278    }
279  ]
280}
281using System.Collections;
282using System.Collections.Generic;
283using UnityEngine;
284
285public class TonePlayer : MonoBehaviour
286{
287    private KeyCode[] keys;
288    public float minAlpha = 80f;
289    public float reduceAlphaStep = 1f;
290    public ToneManager mgr;
291    public SongManager smgr;
292    private void Awake()
293    {
294        StartCoroutine(lightUp());
295        keys = new KeyCode[4] { KeyCode.A, KeyCode.S, KeyCode.D, KeyCode.F };
296    }
297    IEnumerator lightUp()
298    {
299    
300        Dictionary&lt;string[], int&gt; notes = smgr.LoadSong(&quot;Assets/test.unf&quot;);
301        Dictionary&lt;int, string&gt; notes_enc = new Dictionary&lt;int, string&gt;();
302        notes_enc[0] = &quot;C&quot;;
303        notes_enc[1] = &quot;D&quot;;
304        notes_enc[2] = &quot;E&quot;;
305        notes_enc[3] = &quot;F&quot;;
306        for (int i = 0; i &lt; notes.Count; i++)
307        {
308            string[][] keys=new string[notes.Count][];
309            keys[0]= new string[notes.Count];
310            keys[1] = new string[2];
311            notes.Keys.CopyTo(keys, 0);
312            string time = keys[i][0];
313            string duration = keys[i][1];
314            string[] timing = { time, duration };
315            mgr.source.PlayOneShot(mgr.tones[notes[timing]]);
316            print(notes_enc[notes[timing]]);
317            print(duration);
318            yield return new WaitForSeconds(float.Parse(duration));
319        }
320        yield return null;
321    }
322    void Update()
323    {
324        for (int i = 0; i &lt; 4; i++)
325        {
326            if (Input.GetKeyDown(keys[i]))
327            {
328                mgr.source.PlayOneShot(mgr.tones[i]);
329                var temp = mgr.lights[i].color;
330                temp.a = 1;
331                //print(&quot;set&quot;);
332                mgr.lights[i].color = temp;
333            }
334            float alpha = mgr.lights[i].color.a;
335
336            if (alpha &gt; (minAlpha / 255f))
337            {
338                alpha -= (reduceAlphaStep / 255f);
339                var temp = mgr.lights[i].color;
340                temp.a = alpha;
341                mgr.lights[i].color = temp;
342                //print(alpha);
343            }
344        }
345    }
346}
347

SongManager.cs:

1KeyNotFoundException: The given key was not present in the dictionary.
2System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at &lt;695d1cc93cca45069c528c15c9fdd749&gt;:0)
3TonePlayer+&lt;lightUp&gt;d__6.MoveNext () (at Assets/TonePlayer.cs:43)
4UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at &lt;0ee480759f3d481d82ada245dc74f9fd&gt;:0)
5UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
6TonePlayer:Awake() (at Assets/TonePlayer.cs:14)
7{
8  &quot;header&quot;: {
9    &quot;PPQ&quot;: 480,
10    &quot;timeSignature&quot;: [
11      4,
12      4
13    ],
14    &quot;bpm&quot;: 120,
15    &quot;name&quot;: &quot;Piano&quot;
16  },
17  &quot;tempo&quot;: [
18    {
19      &quot;absoluteTime&quot;: 0,
20      &quot;seconds&quot;: 0,
21      &quot;bpm&quot;: 120
22    }
23  ],
24  &quot;timeSignature&quot;: [
25    {
26      &quot;absoluteTime&quot;: 0,
27      &quot;seconds&quot;: 0,
28      &quot;numerator&quot;: 4,
29      &quot;denominator&quot;: 2,
30      &quot;click&quot;: 24,
31      &quot;notesQ&quot;: 8
32    }
33  ],
34  &quot;startTime&quot;: 0,
35  &quot;duration&quot;: 9.223958333333334,
36  &quot;tracks&quot;: [
37    {
38      &quot;startTime&quot;: 0,
39      &quot;duration&quot;: 9.223958333333334,
40      &quot;length&quot;: 26,
41      &quot;notes&quot;: [
42        {
43          &quot;name&quot;: &quot;E5&quot;,
44          &quot;midi&quot;: 76,
45          &quot;time&quot;: 0,
46          &quot;velocity&quot;: 0.6299212598425197,
47          &quot;duration&quot;: 0.23645833333333333
48        },
49        {
50          &quot;name&quot;: &quot;E5&quot;,
51          &quot;midi&quot;: 76,
52          &quot;time&quot;: 0.25,
53          &quot;velocity&quot;: 0.6299212598425197,
54          &quot;duration&quot;: 0.23645833333333333
55        },
56        {
57          &quot;name&quot;: &quot;E5&quot;,
58          &quot;midi&quot;: 76,
59          &quot;time&quot;: 0.5,
60          &quot;velocity&quot;: 0.6299212598425197,
61          &quot;duration&quot;: 0.23645833333333333
62        },
63        {
64          &quot;name&quot;: &quot;C5&quot;,
65          &quot;midi&quot;: 72,
66          &quot;time&quot;: 0.75,
67          &quot;velocity&quot;: 0.6299212598425197,
68          &quot;duration&quot;: 0.23645833333333333
69        },
70        {
71          &quot;name&quot;: &quot;C5&quot;,
72          &quot;midi&quot;: 72,
73          &quot;time&quot;: 1,
74          &quot;velocity&quot;: 0.6299212598425197,
75          &quot;duration&quot;: 0.23645833333333321
76        },
77        {
78          &quot;name&quot;: &quot;C5&quot;,
79          &quot;midi&quot;: 72,
80          &quot;time&quot;: 1.2499999999999998,
81          &quot;velocity&quot;: 0.6299212598425197,
82          &quot;duration&quot;: 0.47395833333333326
83        },
84        {
85          &quot;name&quot;: &quot;C5&quot;,
86          &quot;midi&quot;: 72,
87          &quot;time&quot;: 1.9999999999999998,
88          &quot;velocity&quot;: 0.6299212598425197,
89          &quot;duration&quot;: 0.23645833333333344
90        },
91        {
92          &quot;name&quot;: &quot;D5&quot;,
93          &quot;midi&quot;: 74,
94          &quot;time&quot;: 2.25,
95          &quot;velocity&quot;: 0.6299212598425197,
96          &quot;duration&quot;: 0.23645833333333321
97        },
98        {
99          &quot;name&quot;: &quot;F5&quot;,
100          &quot;midi&quot;: 77,
101          &quot;time&quot;: 2.5,
102          &quot;velocity&quot;: 0.6299212598425197,
103          &quot;duration&quot;: 0.4739583333333335
104        },
105        {
106          &quot;name&quot;: &quot;E5&quot;,
107          &quot;midi&quot;: 76,
108          &quot;time&quot;: 3,
109          &quot;velocity&quot;: 0.6299212598425197,
110          &quot;duration&quot;: 0.4739583333333335
111        },
112        {
113          &quot;name&quot;: &quot;D5&quot;,
114          &quot;midi&quot;: 74,
115          &quot;time&quot;: 3.5,
116          &quot;velocity&quot;: 0.6299212598425197,
117          &quot;duration&quot;: 0.23645833333333321
118        },
119        {
120          &quot;name&quot;: &quot;C5&quot;,
121          &quot;midi&quot;: 72,
122          &quot;time&quot;: 3.75,
123          &quot;velocity&quot;: 0.6299212598425197,
124          &quot;duration&quot;: 0.23645833333333321
125        },
126        {
127          &quot;name&quot;: &quot;E5&quot;,
128          &quot;midi&quot;: 76,
129          &quot;time&quot;: 4,
130          &quot;velocity&quot;: 0.6299212598425197,
131          &quot;duration&quot;: 0.23645833333333321
132        },
133        {
134          &quot;name&quot;: &quot;E5&quot;,
135          &quot;midi&quot;: 76,
136          &quot;time&quot;: 4.25,
137          &quot;velocity&quot;: 0.6299212598425197,
138          &quot;duration&quot;: 0.23645833333333321
139        },
140        {
141          &quot;name&quot;: &quot;E5&quot;,
142          &quot;midi&quot;: 76,
143          &quot;time&quot;: 4.5,
144          &quot;velocity&quot;: 0.6299212598425197,
145          &quot;duration&quot;: 0.23645833333333321
146        },
147        {
148          &quot;name&quot;: &quot;C5&quot;,
149          &quot;midi&quot;: 72,
150          &quot;time&quot;: 4.75,
151          &quot;velocity&quot;: 0.6299212598425197,
152          &quot;duration&quot;: 0.23645833333333321
153        },
154        {
155          &quot;name&quot;: &quot;C5&quot;,
156          &quot;midi&quot;: 72,
157          &quot;time&quot;: 5,
158          &quot;velocity&quot;: 0.6299212598425197,
159          &quot;duration&quot;: 0.23645833333333321
160        },
161        {
162          &quot;name&quot;: &quot;C5&quot;,
163          &quot;midi&quot;: 72,
164          &quot;time&quot;: 5.25,
165          &quot;velocity&quot;: 0.6299212598425197,
166          &quot;duration&quot;: 0.47395833333333304
167        },
168        {
169          &quot;name&quot;: &quot;D5&quot;,
170          &quot;midi&quot;: 74,
171          &quot;time&quot;: 6.75,
172          &quot;velocity&quot;: 0.6299212598425197,
173          &quot;duration&quot;: 0.23645833333333321
174        },
175        {
176          &quot;name&quot;: &quot;D5&quot;,
177          &quot;midi&quot;: 74,
178          &quot;time&quot;: 7,
179          &quot;velocity&quot;: 0.6299212598425197,
180          &quot;duration&quot;: 0.23645833333333321
181        },
182        {
183          &quot;name&quot;: &quot;D5&quot;,
184          &quot;midi&quot;: 74,
185          &quot;time&quot;: 7.25,
186          &quot;velocity&quot;: 0.6299212598425197,
187          &quot;duration&quot;: 0.23645833333333321
188        },
189        {
190          &quot;name&quot;: &quot;D5&quot;,
191          &quot;midi&quot;: 74,
192          &quot;time&quot;: 7.5,
193          &quot;velocity&quot;: 0.6299212598425197,
194          &quot;duration&quot;: 0.23645833333333321
195        },
196        {
197          &quot;name&quot;: &quot;D5&quot;,
198          &quot;midi&quot;: 74,
199          &quot;time&quot;: 7.75,
200          &quot;velocity&quot;: 0.6299212598425197,
201          &quot;duration&quot;: 0.23645833333333321
202        },
203        {
204          &quot;name&quot;: &quot;C5&quot;,
205          &quot;midi&quot;: 72,
206          &quot;time&quot;: 8,
207          &quot;velocity&quot;: 0.6299212598425197,
208          &quot;duration&quot;: 0.23645833333333321
209        },
210        {
211          &quot;name&quot;: &quot;D5&quot;,
212          &quot;midi&quot;: 74,
213          &quot;time&quot;: 8.25,
214          &quot;velocity&quot;: 0.6299212598425197,
215          &quot;duration&quot;: 0.4739583333333339
216        },
217        {
218          &quot;name&quot;: &quot;E5&quot;,
219          &quot;midi&quot;: 76,
220          &quot;time&quot;: 8.75,
221          &quot;velocity&quot;: 0.6299212598425197,
222          &quot;duration&quot;: 0.4739583333333339
223        }
224      ],
225      &quot;controlChanges&quot;: {
226        &quot;7&quot;: [
227          {
228            &quot;number&quot;: 7,
229            &quot;time&quot;: 0,
230            &quot;value&quot;: 0.7874015748031497
231          }
232        ],
233        &quot;10&quot;: [
234          {
235            &quot;number&quot;: 10,
236            &quot;time&quot;: 0,
237            &quot;value&quot;: 0.5039370078740157
238          }
239        ],
240        &quot;91&quot;: [
241          {
242            &quot;number&quot;: 91,
243            &quot;time&quot;: 0,
244            &quot;value&quot;: 0
245          }
246        ],
247        &quot;93&quot;: [
248          {
249            &quot;number&quot;: 93,
250            &quot;time&quot;: 0,
251            &quot;value&quot;: 0
252          }
253        ],
254        &quot;121&quot;: [
255          {
256            &quot;number&quot;: 121,
257            &quot;time&quot;: 0,
258            &quot;value&quot;: 0
259          }
260        ]
261      },
262      &quot;id&quot;: 0,
263      &quot;name&quot;: &quot;Piano&quot;,
264      &quot;instrumentNumber&quot;: 0,
265      &quot;instrument&quot;: &quot;acoustic grand piano&quot;,
266      &quot;instrumentFamily&quot;: &quot;piano&quot;,
267      &quot;channelNumber&quot;: 0,
268      &quot;isPercussion&quot;: false
269    },
270    {
271      &quot;startTime&quot;: 0,
272      &quot;duration&quot;: 0,
273      &quot;length&quot;: 0,
274      &quot;notes&quot;: [],
275      &quot;controlChanges&quot;: {},
276      &quot;id&quot;: 1,
277      &quot;name&quot;: &quot;Piano&quot;
278    }
279  ]
280}
281using System.Collections;
282using System.Collections.Generic;
283using UnityEngine;
284
285public class TonePlayer : MonoBehaviour
286{
287    private KeyCode[] keys;
288    public float minAlpha = 80f;
289    public float reduceAlphaStep = 1f;
290    public ToneManager mgr;
291    public SongManager smgr;
292    private void Awake()
293    {
294        StartCoroutine(lightUp());
295        keys = new KeyCode[4] { KeyCode.A, KeyCode.S, KeyCode.D, KeyCode.F };
296    }
297    IEnumerator lightUp()
298    {
299    
300        Dictionary&lt;string[], int&gt; notes = smgr.LoadSong(&quot;Assets/test.unf&quot;);
301        Dictionary&lt;int, string&gt; notes_enc = new Dictionary&lt;int, string&gt;();
302        notes_enc[0] = &quot;C&quot;;
303        notes_enc[1] = &quot;D&quot;;
304        notes_enc[2] = &quot;E&quot;;
305        notes_enc[3] = &quot;F&quot;;
306        for (int i = 0; i &lt; notes.Count; i++)
307        {
308            string[][] keys=new string[notes.Count][];
309            keys[0]= new string[notes.Count];
310            keys[1] = new string[2];
311            notes.Keys.CopyTo(keys, 0);
312            string time = keys[i][0];
313            string duration = keys[i][1];
314            string[] timing = { time, duration };
315            mgr.source.PlayOneShot(mgr.tones[notes[timing]]);
316            print(notes_enc[notes[timing]]);
317            print(duration);
318            yield return new WaitForSeconds(float.Parse(duration));
319        }
320        yield return null;
321    }
322    void Update()
323    {
324        for (int i = 0; i &lt; 4; i++)
325        {
326            if (Input.GetKeyDown(keys[i]))
327            {
328                mgr.source.PlayOneShot(mgr.tones[i]);
329                var temp = mgr.lights[i].color;
330                temp.a = 1;
331                //print(&quot;set&quot;);
332                mgr.lights[i].color = temp;
333            }
334            float alpha = mgr.lights[i].color.a;
335
336            if (alpha &gt; (minAlpha / 255f))
337            {
338                alpha -= (reduceAlphaStep / 255f);
339                var temp = mgr.lights[i].color;
340                temp.a = alpha;
341                mgr.lights[i].color = temp;
342                //print(alpha);
343            }
344        }
345    }
346}
347using System.Collections;
348using System.Collections.Generic;
349using Newtonsoft.Json.Linq;
350using System.IO;
351using System;
352using UnityEngine;
353
354public class SongManager : MonoBehaviour
355{
356    public string[] first;
357    private void Awake()
358    {
359        LoadSong(&quot;Assets/test.unf&quot;);
360    }
361    public Dictionary&lt;string[], int&gt; LoadSong(string unf_json)
362    {
363        Dictionary&lt;string[], int&gt; ret = new Dictionary&lt;string[], int&gt;();
364        string json = File.ReadAllText(unf_json);
365        var root = JObject.Parse(json);
366        var tracks = root.GetValue(&quot;tracks&quot;)[0][&quot;notes&quot;];
367        Dictionary&lt;string, int&gt; notes_enc = new Dictionary&lt;string, int&gt;();
368        notes_enc[&quot;C&quot;] = 0;
369        notes_enc[&quot;D&quot;] = 1;
370        notes_enc[&quot;E&quot;] = 2;
371        notes_enc[&quot;F&quot;] = 3;
372        int z = 0;
373        foreach (var track in tracks)
374        {
375            z++;
376            float time = ((float)track[&quot;time&quot;]);
377            float duration = ((float)track[&quot;duration&quot;]);
378            string[] timings = { time.ToString(&quot;0.000&quot;), duration.ToString(&quot;0.000&quot;) };
379            string name = ((string)track[&quot;name&quot;])[0].ToString();
380
381
382
383            //Debug.Log(string.Format(&quot;duration: {0}, note: {1}({2})&quot;, duration, name, notes_enc[name]));
384            ret[timings] = notes_enc[name];
385        }
386        return ret;
387    }
388}
389

ToneManager.cs:

1KeyNotFoundException: The given key was not present in the dictionary.
2System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at &lt;695d1cc93cca45069c528c15c9fdd749&gt;:0)
3TonePlayer+&lt;lightUp&gt;d__6.MoveNext () (at Assets/TonePlayer.cs:43)
4UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at &lt;0ee480759f3d481d82ada245dc74f9fd&gt;:0)
5UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
6TonePlayer:Awake() (at Assets/TonePlayer.cs:14)
7{
8  &quot;header&quot;: {
9    &quot;PPQ&quot;: 480,
10    &quot;timeSignature&quot;: [
11      4,
12      4
13    ],
14    &quot;bpm&quot;: 120,
15    &quot;name&quot;: &quot;Piano&quot;
16  },
17  &quot;tempo&quot;: [
18    {
19      &quot;absoluteTime&quot;: 0,
20      &quot;seconds&quot;: 0,
21      &quot;bpm&quot;: 120
22    }
23  ],
24  &quot;timeSignature&quot;: [
25    {
26      &quot;absoluteTime&quot;: 0,
27      &quot;seconds&quot;: 0,
28      &quot;numerator&quot;: 4,
29      &quot;denominator&quot;: 2,
30      &quot;click&quot;: 24,
31      &quot;notesQ&quot;: 8
32    }
33  ],
34  &quot;startTime&quot;: 0,
35  &quot;duration&quot;: 9.223958333333334,
36  &quot;tracks&quot;: [
37    {
38      &quot;startTime&quot;: 0,
39      &quot;duration&quot;: 9.223958333333334,
40      &quot;length&quot;: 26,
41      &quot;notes&quot;: [
42        {
43          &quot;name&quot;: &quot;E5&quot;,
44          &quot;midi&quot;: 76,
45          &quot;time&quot;: 0,
46          &quot;velocity&quot;: 0.6299212598425197,
47          &quot;duration&quot;: 0.23645833333333333
48        },
49        {
50          &quot;name&quot;: &quot;E5&quot;,
51          &quot;midi&quot;: 76,
52          &quot;time&quot;: 0.25,
53          &quot;velocity&quot;: 0.6299212598425197,
54          &quot;duration&quot;: 0.23645833333333333
55        },
56        {
57          &quot;name&quot;: &quot;E5&quot;,
58          &quot;midi&quot;: 76,
59          &quot;time&quot;: 0.5,
60          &quot;velocity&quot;: 0.6299212598425197,
61          &quot;duration&quot;: 0.23645833333333333
62        },
63        {
64          &quot;name&quot;: &quot;C5&quot;,
65          &quot;midi&quot;: 72,
66          &quot;time&quot;: 0.75,
67          &quot;velocity&quot;: 0.6299212598425197,
68          &quot;duration&quot;: 0.23645833333333333
69        },
70        {
71          &quot;name&quot;: &quot;C5&quot;,
72          &quot;midi&quot;: 72,
73          &quot;time&quot;: 1,
74          &quot;velocity&quot;: 0.6299212598425197,
75          &quot;duration&quot;: 0.23645833333333321
76        },
77        {
78          &quot;name&quot;: &quot;C5&quot;,
79          &quot;midi&quot;: 72,
80          &quot;time&quot;: 1.2499999999999998,
81          &quot;velocity&quot;: 0.6299212598425197,
82          &quot;duration&quot;: 0.47395833333333326
83        },
84        {
85          &quot;name&quot;: &quot;C5&quot;,
86          &quot;midi&quot;: 72,
87          &quot;time&quot;: 1.9999999999999998,
88          &quot;velocity&quot;: 0.6299212598425197,
89          &quot;duration&quot;: 0.23645833333333344
90        },
91        {
92          &quot;name&quot;: &quot;D5&quot;,
93          &quot;midi&quot;: 74,
94          &quot;time&quot;: 2.25,
95          &quot;velocity&quot;: 0.6299212598425197,
96          &quot;duration&quot;: 0.23645833333333321
97        },
98        {
99          &quot;name&quot;: &quot;F5&quot;,
100          &quot;midi&quot;: 77,
101          &quot;time&quot;: 2.5,
102          &quot;velocity&quot;: 0.6299212598425197,
103          &quot;duration&quot;: 0.4739583333333335
104        },
105        {
106          &quot;name&quot;: &quot;E5&quot;,
107          &quot;midi&quot;: 76,
108          &quot;time&quot;: 3,
109          &quot;velocity&quot;: 0.6299212598425197,
110          &quot;duration&quot;: 0.4739583333333335
111        },
112        {
113          &quot;name&quot;: &quot;D5&quot;,
114          &quot;midi&quot;: 74,
115          &quot;time&quot;: 3.5,
116          &quot;velocity&quot;: 0.6299212598425197,
117          &quot;duration&quot;: 0.23645833333333321
118        },
119        {
120          &quot;name&quot;: &quot;C5&quot;,
121          &quot;midi&quot;: 72,
122          &quot;time&quot;: 3.75,
123          &quot;velocity&quot;: 0.6299212598425197,
124          &quot;duration&quot;: 0.23645833333333321
125        },
126        {
127          &quot;name&quot;: &quot;E5&quot;,
128          &quot;midi&quot;: 76,
129          &quot;time&quot;: 4,
130          &quot;velocity&quot;: 0.6299212598425197,
131          &quot;duration&quot;: 0.23645833333333321
132        },
133        {
134          &quot;name&quot;: &quot;E5&quot;,
135          &quot;midi&quot;: 76,
136          &quot;time&quot;: 4.25,
137          &quot;velocity&quot;: 0.6299212598425197,
138          &quot;duration&quot;: 0.23645833333333321
139        },
140        {
141          &quot;name&quot;: &quot;E5&quot;,
142          &quot;midi&quot;: 76,
143          &quot;time&quot;: 4.5,
144          &quot;velocity&quot;: 0.6299212598425197,
145          &quot;duration&quot;: 0.23645833333333321
146        },
147        {
148          &quot;name&quot;: &quot;C5&quot;,
149          &quot;midi&quot;: 72,
150          &quot;time&quot;: 4.75,
151          &quot;velocity&quot;: 0.6299212598425197,
152          &quot;duration&quot;: 0.23645833333333321
153        },
154        {
155          &quot;name&quot;: &quot;C5&quot;,
156          &quot;midi&quot;: 72,
157          &quot;time&quot;: 5,
158          &quot;velocity&quot;: 0.6299212598425197,
159          &quot;duration&quot;: 0.23645833333333321
160        },
161        {
162          &quot;name&quot;: &quot;C5&quot;,
163          &quot;midi&quot;: 72,
164          &quot;time&quot;: 5.25,
165          &quot;velocity&quot;: 0.6299212598425197,
166          &quot;duration&quot;: 0.47395833333333304
167        },
168        {
169          &quot;name&quot;: &quot;D5&quot;,
170          &quot;midi&quot;: 74,
171          &quot;time&quot;: 6.75,
172          &quot;velocity&quot;: 0.6299212598425197,
173          &quot;duration&quot;: 0.23645833333333321
174        },
175        {
176          &quot;name&quot;: &quot;D5&quot;,
177          &quot;midi&quot;: 74,
178          &quot;time&quot;: 7,
179          &quot;velocity&quot;: 0.6299212598425197,
180          &quot;duration&quot;: 0.23645833333333321
181        },
182        {
183          &quot;name&quot;: &quot;D5&quot;,
184          &quot;midi&quot;: 74,
185          &quot;time&quot;: 7.25,
186          &quot;velocity&quot;: 0.6299212598425197,
187          &quot;duration&quot;: 0.23645833333333321
188        },
189        {
190          &quot;name&quot;: &quot;D5&quot;,
191          &quot;midi&quot;: 74,
192          &quot;time&quot;: 7.5,
193          &quot;velocity&quot;: 0.6299212598425197,
194          &quot;duration&quot;: 0.23645833333333321
195        },
196        {
197          &quot;name&quot;: &quot;D5&quot;,
198          &quot;midi&quot;: 74,
199          &quot;time&quot;: 7.75,
200          &quot;velocity&quot;: 0.6299212598425197,
201          &quot;duration&quot;: 0.23645833333333321
202        },
203        {
204          &quot;name&quot;: &quot;C5&quot;,
205          &quot;midi&quot;: 72,
206          &quot;time&quot;: 8,
207          &quot;velocity&quot;: 0.6299212598425197,
208          &quot;duration&quot;: 0.23645833333333321
209        },
210        {
211          &quot;name&quot;: &quot;D5&quot;,
212          &quot;midi&quot;: 74,
213          &quot;time&quot;: 8.25,
214          &quot;velocity&quot;: 0.6299212598425197,
215          &quot;duration&quot;: 0.4739583333333339
216        },
217        {
218          &quot;name&quot;: &quot;E5&quot;,
219          &quot;midi&quot;: 76,
220          &quot;time&quot;: 8.75,
221          &quot;velocity&quot;: 0.6299212598425197,
222          &quot;duration&quot;: 0.4739583333333339
223        }
224      ],
225      &quot;controlChanges&quot;: {
226        &quot;7&quot;: [
227          {
228            &quot;number&quot;: 7,
229            &quot;time&quot;: 0,
230            &quot;value&quot;: 0.7874015748031497
231          }
232        ],
233        &quot;10&quot;: [
234          {
235            &quot;number&quot;: 10,
236            &quot;time&quot;: 0,
237            &quot;value&quot;: 0.5039370078740157
238          }
239        ],
240        &quot;91&quot;: [
241          {
242            &quot;number&quot;: 91,
243            &quot;time&quot;: 0,
244            &quot;value&quot;: 0
245          }
246        ],
247        &quot;93&quot;: [
248          {
249            &quot;number&quot;: 93,
250            &quot;time&quot;: 0,
251            &quot;value&quot;: 0
252          }
253        ],
254        &quot;121&quot;: [
255          {
256            &quot;number&quot;: 121,
257            &quot;time&quot;: 0,
258            &quot;value&quot;: 0
259          }
260        ]
261      },
262      &quot;id&quot;: 0,
263      &quot;name&quot;: &quot;Piano&quot;,
264      &quot;instrumentNumber&quot;: 0,
265      &quot;instrument&quot;: &quot;acoustic grand piano&quot;,
266      &quot;instrumentFamily&quot;: &quot;piano&quot;,
267      &quot;channelNumber&quot;: 0,
268      &quot;isPercussion&quot;: false
269    },
270    {
271      &quot;startTime&quot;: 0,
272      &quot;duration&quot;: 0,
273      &quot;length&quot;: 0,
274      &quot;notes&quot;: [],
275      &quot;controlChanges&quot;: {},
276      &quot;id&quot;: 1,
277      &quot;name&quot;: &quot;Piano&quot;
278    }
279  ]
280}
281using System.Collections;
282using System.Collections.Generic;
283using UnityEngine;
284
285public class TonePlayer : MonoBehaviour
286{
287    private KeyCode[] keys;
288    public float minAlpha = 80f;
289    public float reduceAlphaStep = 1f;
290    public ToneManager mgr;
291    public SongManager smgr;
292    private void Awake()
293    {
294        StartCoroutine(lightUp());
295        keys = new KeyCode[4] { KeyCode.A, KeyCode.S, KeyCode.D, KeyCode.F };
296    }
297    IEnumerator lightUp()
298    {
299    
300        Dictionary&lt;string[], int&gt; notes = smgr.LoadSong(&quot;Assets/test.unf&quot;);
301        Dictionary&lt;int, string&gt; notes_enc = new Dictionary&lt;int, string&gt;();
302        notes_enc[0] = &quot;C&quot;;
303        notes_enc[1] = &quot;D&quot;;
304        notes_enc[2] = &quot;E&quot;;
305        notes_enc[3] = &quot;F&quot;;
306        for (int i = 0; i &lt; notes.Count; i++)
307        {
308            string[][] keys=new string[notes.Count][];
309            keys[0]= new string[notes.Count];
310            keys[1] = new string[2];
311            notes.Keys.CopyTo(keys, 0);
312            string time = keys[i][0];
313            string duration = keys[i][1];
314            string[] timing = { time, duration };
315            mgr.source.PlayOneShot(mgr.tones[notes[timing]]);
316            print(notes_enc[notes[timing]]);
317            print(duration);
318            yield return new WaitForSeconds(float.Parse(duration));
319        }
320        yield return null;
321    }
322    void Update()
323    {
324        for (int i = 0; i &lt; 4; i++)
325        {
326            if (Input.GetKeyDown(keys[i]))
327            {
328                mgr.source.PlayOneShot(mgr.tones[i]);
329                var temp = mgr.lights[i].color;
330                temp.a = 1;
331                //print(&quot;set&quot;);
332                mgr.lights[i].color = temp;
333            }
334            float alpha = mgr.lights[i].color.a;
335
336            if (alpha &gt; (minAlpha / 255f))
337            {
338                alpha -= (reduceAlphaStep / 255f);
339                var temp = mgr.lights[i].color;
340                temp.a = alpha;
341                mgr.lights[i].color = temp;
342                //print(alpha);
343            }
344        }
345    }
346}
347using System.Collections;
348using System.Collections.Generic;
349using Newtonsoft.Json.Linq;
350using System.IO;
351using System;
352using UnityEngine;
353
354public class SongManager : MonoBehaviour
355{
356    public string[] first;
357    private void Awake()
358    {
359        LoadSong(&quot;Assets/test.unf&quot;);
360    }
361    public Dictionary&lt;string[], int&gt; LoadSong(string unf_json)
362    {
363        Dictionary&lt;string[], int&gt; ret = new Dictionary&lt;string[], int&gt;();
364        string json = File.ReadAllText(unf_json);
365        var root = JObject.Parse(json);
366        var tracks = root.GetValue(&quot;tracks&quot;)[0][&quot;notes&quot;];
367        Dictionary&lt;string, int&gt; notes_enc = new Dictionary&lt;string, int&gt;();
368        notes_enc[&quot;C&quot;] = 0;
369        notes_enc[&quot;D&quot;] = 1;
370        notes_enc[&quot;E&quot;] = 2;
371        notes_enc[&quot;F&quot;] = 3;
372        int z = 0;
373        foreach (var track in tracks)
374        {
375            z++;
376            float time = ((float)track[&quot;time&quot;]);
377            float duration = ((float)track[&quot;duration&quot;]);
378            string[] timings = { time.ToString(&quot;0.000&quot;), duration.ToString(&quot;0.000&quot;) };
379            string name = ((string)track[&quot;name&quot;])[0].ToString();
380
381
382
383            //Debug.Log(string.Format(&quot;duration: {0}, note: {1}({2})&quot;, duration, name, notes_enc[name]));
384            ret[timings] = notes_enc[name];
385        }
386        return ret;
387    }
388}
389using System.Collections;
390using System.Collections.Generic;
391using System;
392using UnityEngine;
393
394public class ToneManager : MonoBehaviour
395{
396    public AudioSource source;
397    public AudioClip[] tones;
398
399    [HideInInspector]
400    public SpriteRenderer[] lights;
401    public Transform parent;
402    public TonePlayer player;
403    private void Start()
404    {
405        lights = GetSpriteRenderers(GetChildren(parent));
406        /*for (int i = 0; i &lt; 4; i++)
407        {
408            lights[i].color = SetAlpha(lights[i].color, player.minAlpha);
409        }
410        */
411    }
412    public Transform[] GetChildren(Transform parent)
413    {
414        List&lt;Transform&gt; children = new List&lt;Transform&gt;();
415        for (int i = 0; i &lt; parent.childCount; i++)
416        {
417            children.Add(parent.GetChild(i));
418        }
419        return children.ToArray();
420    }
421    public SpriteRenderer[] GetSpriteRenderers(Transform[] children)
422    {
423        SpriteRenderer[] spriteRenderers = new SpriteRenderer[children.Length];
424        for (int i = 0; i &lt; children.Length; i++)
425        {
426            spriteRenderers[i] = children[i].GetComponent&lt;SpriteRenderer&gt;();
427        }
428        return spriteRenderers;
429    }
430}
431

ANSWER

Answered 2021-Dec-25 at 14:11

From what I can see, in your SongManager you are creating Dictionary<string[], int> ret, but not adding any values to. Instead, you are trying to directly assign values: ret[timings] = notes_enc[name];. Dictionary is not an array, you should use Add() method, like this: ret.Add(timings, notes_enc[name]);

Source https://stackoverflow.com/questions/70480242

QUESTION

Webaudio timing performance

Asked 2021-Nov-02 at 12:49

The file below uses ToneJS to play a steam of steady 8th notes. According to the log of the timing, those 8th notes are precisely 0.25 seconds apart.

However, they don't sound even. The time intervals between the notes are distinctly irregular.

Why is it so? Is there anything that can be done about it? Or is this a performance limitation of Javascript/webaudio-api? I have tested it in Chrome, Firefox, and Safari, all to the same result.

Thanks for any information or suggestions about this!

1&lt;!DOCTYPE html&gt;
2&lt;html&gt;
3&lt;head&gt;
4&lt;title&gt;Tone Timing Tester&lt;/title&gt;
5&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.32/Tone.min.js&quot;&gt;&lt;/script&gt;
6&lt;/head&gt;
7
8&lt;body&gt;
9&lt;button onclick=&quot;start()&quot;&gt;Start&lt;/button&gt;
10&lt;button onclick=&quot;stop()&quot;&gt;Stop&lt;/button&gt;
11&lt;form&gt;
12    &lt;input id=&quot;bpm&quot; type=&quot;number&quot; value=&quot;120&quot;&gt;
13    &lt;button type=&quot;button&quot; onclick=&quot;submitBPM()&quot;&gt;Enter BPM&lt;/button&gt;
14&lt;/form&gt;
15
16&lt;script type=&quot;text/javascript&quot;&gt;
17    
18    var synth = new Tone.Synth().toDestination()
19
20    Tone.Transport.scheduleRepeat(function(time){
21        console.log('time', time);
22        synth.triggerAttackRelease('C4', '8n')
23    }, &quot;8n&quot;);
24
25    async function start() {
26        await Tone.start()
27        Tone.Transport.start();
28    }
29
30    function stop() {
31        Tone.Transport.stop();
32    }
33
34    function submitBPM() {
35        var bpm = document.getElementById('bpm').value;
36        Tone.Transport.bpm.value = bpm;
37    }
38
39&lt;/script&gt;
40&lt;/body&gt;
41&lt;/html&gt;
42

ANSWER

Answered 2021-Nov-02 at 12:49

For a scheduled triggerAttackRelease, you should pass the time value as the third argument.

1&lt;!DOCTYPE html&gt;
2&lt;html&gt;
3&lt;head&gt;
4&lt;title&gt;Tone Timing Tester&lt;/title&gt;
5&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/tone/14.8.32/Tone.min.js&quot;&gt;&lt;/script&gt;
6&lt;/head&gt;
7
8&lt;body&gt;
9&lt;button onclick=&quot;start()&quot;&gt;Start&lt;/button&gt;
10&lt;button onclick=&quot;stop()&quot;&gt;Stop&lt;/button&gt;
11&lt;form&gt;
12    &lt;input id=&quot;bpm&quot; type=&quot;number&quot; value=&quot;120&quot;&gt;
13    &lt;button type=&quot;button&quot; onclick=&quot;submitBPM()&quot;&gt;Enter BPM&lt;/button&gt;
14&lt;/form&gt;
15
16&lt;script type=&quot;text/javascript&quot;&gt;
17    
18    var synth = new Tone.Synth().toDestination()
19
20    Tone.Transport.scheduleRepeat(function(time){
21        console.log('time', time);
22        synth.triggerAttackRelease('C4', '8n')
23    }, &quot;8n&quot;);
24
25    async function start() {
26        await Tone.start()
27        Tone.Transport.start();
28    }
29
30    function stop() {
31        Tone.Transport.stop();
32    }
33
34    function submitBPM() {
35        var bpm = document.getElementById('bpm').value;
36        Tone.Transport.bpm.value = bpm;
37    }
38
39&lt;/script&gt;
40&lt;/body&gt;
41&lt;/html&gt;
42Tone.Transport.scheduleRepeat(function(time){
43    console.log('time', time);
44    synth.triggerAttackRelease('C4', '8n', time);
45}, &quot;8n&quot;);
46

Here's a codepen that contains the working code.

Source https://stackoverflow.com/questions/69804550

Community Discussions contain sources that include Stack Exchange Network

Tutorials and Learning Resources in BPM

Tutorials and Learning Resources are not available at this moment for BPM

Share this Page

share link

Get latest updates on BPM